Re: how can we check to not enter the any string or char?
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Wed, 31 Oct 2007 14:50:15 -0700
John Gordon <gordon@xxxxxxxxx> writes:
In <1193862410.106448.76840@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> "emre[code snipped]
esirik(hacettepe computer science and engineering)"
<emreesirik@xxxxxxxxx> writes:
int n_mines;
printf("How many mines do you want in the minefield?");
scanf("%d", &n_mines);
while(n_mines>100 || n_mines<0)
{
printf("Please only enter between 1 and 100");
scanf("%d", &n_mines);
}
so I dont want to user can enter the string or char value,how can I
check it?
Read the input as a string first. Examine the string to see if it contains
any incorrect characters. If it does not, convert the string to its
decimal value.
And if you choose to use scanf or (or fscanf or sscanf), remember that
it returns a value. Read your documentation to find out what the
returned value means, and *always* check it.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- Follow-Ups:
- Re: how can we check to not enter the any string or char?
- From: vipvipvipvipvip . ru
- Re: how can we check to not enter the any string or char?
- References:
- how can we check to not enter the any string or char?
- From: emre esirik(hacettepe computer science and engineering)
- Re: how can we check to not enter the any string or char?
- From: John Gordon
- how can we check to not enter the any string or char?
- Prev by Date: Re: how can we check to not enter the any string or char?
- Next by Date: Re: how can we check to not enter the any string or char?
- Previous by thread: Re: how can we check to not enter the any string or char?
- Next by thread: Re: how can we check to not enter the any string or char?
- Index(es):
Relevant Pages
|