chcmp.c (1778B)
1 /* Exercise 8.5 */ 2 3 #include <stdio.h> 4 #include <ctype.h> 5 6 int main(void) 7 { 8 char c; 9 10 puts("Give me a char"); 11 c = getchar(); 12 putchar('\n'); 13 14 /* Start the comparision */ 15 printf("%c %s an alpha character (%u)\n", 16 c, isalpha((int)c) ? "is" : "is not", isalpha((int)c)); 17 printf("%c %s an upper character (%u)\n", 18 c, isupper((int)c) ? "is" : "is not", isupper((int)c)); 19 printf("%c %s a lower character (%u)\n", 20 c, islower((int)c) ? "is" : "is not", islower((int)c)); 21 printf("%c %s a digit character (%u)\n", 22 c, isdigit((int)c) ? "is" : "is not", isdigit((int)c)); 23 printf("%c %s a hex digit character (%u)\n", 24 c, isxdigit((int)c) ? "is" : "is not", isxdigit((int)c)); 25 printf("%c %s an alnum character (%u)\n", 26 c, isalnum((int)c) ? "is" : "is not", isalnum((int)c)); 27 printf("%c %s a space character (%u)\n", 28 c, isspace((int)c) ? "is" : "is not", isspace((int)c)); 29 printf("%c %s a punctuation character (%u)\n", 30 c, ispunct((int)c) ? "is" : "is not", ispunct((int)c)); 31 printf("%c %s a printer character (%u)\n", 32 c, isprint((int)c) ? "is" : "is not", isprint((int)c)); 33 printf("%c %s a graphic character (%u)\n", 34 c, isgraph((int)c) ? "is" : "is not", isgraph((int)c)); 35 printf("%c %s a control character (%u)\n", 36 c, iscntrl((int)c) ? "is" : "is not", iscntrl((int)c)); 37 printf("%c %s a blank character (%u)\n", 38 c, isblank((int)c) ? "is" : "is not", isblank((int)c)); 39 printf("%c %s an ASCII character (%u)\n", 40 c, isascii((int)c) ? "is" : "is not", isascii((int)c)); 41 42 printf("%c to upper is %c\n", c, toupper((int)c)); 43 printf("%c to lower is %c\n", c, tolower((int)c)); 44 printf("%c to ASCII is %c\n", c, toascii((int)c)); 45 46 return 0; 47 } /* E0F main */ 48