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



Philip Potter wrote:

Jack Klein wrote:
On Wed, 31 Oct 2007 16:33:33 -0700, andreyvul <andrey.vul@xxxxxxxxx>
wrote in comp.lang.c:

On Oct 31, 6:12 pm, vipvipvipvipvip...@xxxxxxxxx wrote:
fgets() and strtol().
fgets(str, 4, stdin) to be specific

also, there are only up to 4 input bytes, so the loop should be
rewritten to this:
char[4] str;
int i = 0, n_mines = 0;
while (1) {
fgets(str, 4, stdin);
for (i = 0; i < 4; i++)
if ((str[i] < 0x30 && str[i]) || str[i] > 0x39) /* check
ascii
value if it's not */

But what if the platform does not use ASCII? C does not require it.
This is extremely foolish, when using '0' and '9' instead of 0x30 and
0x39 guarantees portability to any implementation of C now and
forever.

It is unlikely but possible that the character set does not have the
digits 0-9 nicely in order. Better to use isdigit().

I think C guarantees that the character sequence '0'... '9' have
sequentially increasing code values.

.