Thread overview | |||||
---|---|---|---|---|---|
|
July 13, 2003 isXXX functions | ||||
---|---|---|---|---|
| ||||
#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 ? |
July 14, 2003 Re: isXXX functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to noobi | 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
|
July 14, 2003 Re: isXXX functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Heinz Saathoff | 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 |
Copyright © 1999-2021 by the D Language Foundation