Re: how can we check to not enter the any string or char?
- From: santosh <santosh.k83@xxxxxxxxx>
- Date: Thu, 01 Nov 2007 18:27:47 +0530
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.
.
- Follow-Ups:
- Re: 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?
- References:
- Re: how can we check to not enter the any string or char?
- From: andreyvul
- Re: how can we check to not enter the any string or char?
- From: Jack Klein
- Re: how can we check to not enter the any string or char?
- From: Philip Potter
- Re: how can we check to not enter the any string or char?
- Prev by Date: Re: Simple allocation of two buffer on AMD64
- Next by Date: Re: Simple allocation of two buffer on AMD64
- 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):