--
int _tmain(int argc, _TCHAR* argv[])
{
char c = -3;
if(isdigit(c))
{
puts("Character '-3' is a digit");
}
else
{
puts("Character '-3' is not a digit");
}
return 0;
}
--
Thanks in advace
lauch2.
The <ctype.h> functions take ints and are defined only on those values of
int that are representable in unsigned char, plus EOF. In VC++ and most
other compilers, plain char is signed, and it's undefined to pass char(-3)
to functions like isdigit, because it gets promoted to int(-3). The
solution is to cast to unsigned char, e.g.
if (isdigit((unsigned char) c)) ...
--
Doug Harrison
VC++ MVP