www.digitalmars.com         C & C++   DMDScript  

c++.dos - isXXX functions

reply noobi <noobi_member pathlink.com> writes:
#include <stdio.h>
#include <ctype.h>

main()
{
int val, test = 2;

val = isdigit(test);
printf("%i \n", test);

if (val != 0) puts("is a digit");
else puts("is not a digit");

return 0;
}


Output :
2
is not a digit

Whats wrong ?
Jul 13 2003
parent reply Heinz Saathoff <hsaat bre.ipnet.de> writes:
noobi schrieb...
 #include <stdio.h>
 #include <ctype.h>
 
 main()
 {
 int val, test = 2;
 
 val = isdigit(test);
 printf("%i \n", test);
 
 if (val != 0) puts("is a digit");
 else puts("is not a digit");
 
 return 0;
 }
 
 
 Output :
 2
 is not a digit
 
 Whats wrong ?
isXXX Functions work for chars (or the integer number of a char). You have assigned the integer 2 to test. Interpreted as a char it's a control char (below the space character in the ASCII table). To assign the ASCII 2 character to test write the assignment as test = '2'; /* ASCII 2 == decimal 50 */ - Heinz
Jul 14 2003
parent noobi <noobi_member pathlink.com> writes:
Big thanks for your help.

In article <MPG.197c7537d2409aa39896c9 news.digitalmars.com>, Heinz Saathoff
says...
noobi schrieb...
 #include <stdio.h>
 #include <ctype.h>
 
 main()
 {
 int val, test = 2;
 
 val = isdigit(test);
 printf("%i \n", test);
 
 if (val != 0) puts("is a digit");
 else puts("is not a digit");
 
 return 0;
 }
 
 
 Output :
 2
 is not a digit
 
 Whats wrong ?
isXXX Functions work for chars (or the integer number of a char). You have assigned the integer 2 to test. Interpreted as a char it's a control char (below the space character in the ASCII table). To assign the ASCII 2 character to test write the assignment as test = '2'; /* ASCII 2 == decimal 50 */ - Heinz
Jul 14 2003