"shafi" <sh*********@gmail.comwrites:
>j=isdigit(9);
k=isdigit('A');
The isdigit() function takes an argument of character type or EOF and
it return non zero value if
the passing argument is characters '0' , '1' . . . '9' else it returns
zero.
More precisely,
... the argument is an int, the value of which shall be
representable as an unsigned char or shall equal the value of the
macro EOF. If the argument has any other value, the behavior is
undefined.
This is an important distinction. Something like this:
char c = some_value;
isdigit(c);
can invoke undefined behavior if (1) plain char is signed, and (2) the
value of c is negative (and not equal to EOF). For arguments other
than EOF, it's often a good idea to cast the argument:
char c = some_value;
isdigit((unsigned char)c);
(This is one of the few cases where a cast is actually a good idea.)
Or, in this case, you could avoid the cast by changing the declaration
of c:
unsigned char c = some_value;
isdigit(c);
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <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.