why 'isdigit' always return zero ?Code:int c=3; char c2='t'; int f1,f2; f1=isdigit(c); printf("%d",f1); // output is 0 f2=isdigit(c2); printf("%d",f2); // output is 0
I thought, I will find something different in 'f2' ?
I'm using C, not C++.
why 'isdigit' always return zero ?Code:int c=3; char c2='t'; int f1,f2; f1=isdigit(c); printf("%d",f1); // output is 0 f2=isdigit(c2); printf("%d",f2); // output is 0
I thought, I will find something different in 'f2' ?
I'm using C, not C++.
Well the short answer is that the integer 1 is not the same as the character '1' and therefore isdigit() will return zero. This is because the character '1' is actually equal to 49 (0x31) when cast to an int. See this link for isdigit() and from that link:
JimParameters
c
Character to be checked, casted to an int, or EOF.
Last edited by jimblumberg; 08-06-2012 at 08:14 PM.
Thanks Jim
your reply, help me to understand the return of this function.
I read this before, and it confuses me !
and since, there is no Boolean type in cReturn Value
A value different from zero (i.e., true) if indeed c is a decimal digit. Zero (i.e., false) otherwise.
I thought, true equal "number different from zero"
false equal zero
English is my second language
best,
Yes, that is correct. In particular, the default "true" value is 1 (but generally you should not rely on this particular value, except where it is guaranteed).Originally Posted by JavaLover
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
just to clarify
so, now if I get 1 means the Var is a digit, zero if it is notCode:char c1='3'; char c2='k'; int f1,f2; f1=isdigit(c1); printf("\n%d",f1); // output is 1 f2=isdigit(c2); printf("\n%d\n",f2); // output is 0