/* * program to demonstrate the ctype macros * print the type of each letter in the argument * * Matt Bishop, ECS 36A, Fall Quarter 2019 */ #include #include /* * main routine */ int main(int argc, char *argv[]) { char *s; /* used to walk down string */ /* * Be sure there's an argument */ if (argc == 1){ fprintf(stderr, "Usage: %s string\n", argv[0]); return(1); } /* * walk the argument, printing the types of chars as we go */ for(s = argv[1]; *s; s++){ printf("The character \'%c\' (\\%03o) is:\n", *s, *s); if (isalnum(*s)) printf("\talphanumeric\n"); if (isalpha(*s)) printf("\talphabetic\n"); if (isupper(*s)) printf("\tupper case\n"); if (islower(*s)) printf("\tlower case\n"); if (isspace(*s)) printf("\twhite space\n"); if (iscntrl(*s)) printf("\ta control character\n"); if (isdigit(*s)) printf("\ta digit\n"); if (isxdigit(*s)) printf("\ta hexadecimal digit\n"); if (ispunct(*s)) printf("\tpunctuation\n"); } /* * done! */ return(0); }