/* * program to demonstrate the ctype macros * print the type of each letter in the argument * * Matt Bishop, ECS 36A * -- April 12, 2024 original version * -- May 23, 2024 addrd isprint, isgraph, tolower, toupper */ #include <stdio.h> #include <ctype.h> /* * 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 (isprint(*s)) printf("\tis printing\n"); if (isgraph(*s)) printf("\tis graphical\n"); if (isalnum(*s)) printf("\talphanumeric\n"); if (isalpha(*s)) printf("\talphabetic\n"); if (isupper(*s)) printf("\tupper case; lower case is '%c'\n", tolower(*s)); if (islower(*s)) printf("\tlower case; upper case is '%c'\n", toupper(*s)); if (islower(*s)) printf("\tlower case\n"); if (isspace(*s)) printf("\twhite space\n"); if (ispunct(*s)) printf("\tpunctuation\n"); if (iscntrl(*s)) printf("\ta control character\n"); if (isdigit(*s)) printf("\ta digit\n"); if (isxdigit(*s)) printf("\ta hexadecimal digit\n"); } /* * done! */ return(0); }
|
ECS 36A, Programming & Problem Solving Version of April 2, 2024 at 12:13PM
|
You can get the raw source code here. |