Re: how can we check to not enter the any string or char?
- From: Philip Potter <pgp@xxxxxxxxxxxxxxx>
- Date: Thu, 01 Nov 2007 12:27:47 +0000
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().
--
Philip Potter pgp <at> doc.ic.ac.uk
.
- Follow-Ups:
- Re: how can we check to not enter the any string or char?
- From: santosh
- Re: how can we check to not enter the any string or char?
- From: Chris Dollin
- 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?
- Prev by Date: Re: Block insert into mysql(5.0)
- 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
|