Re: how can we check to not enter the any string or char?



John Gordon <gordon@xxxxxxxxx> writes:
In <1193862410.106448.76840@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> "emre
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.

[code snipped]

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"
.



Relevant Pages