home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc_prog / chap09 / whatchar.c < prev   
Encoding:
C/C++ Source or Header  |  1988-04-06  |  1.2 KB  |  37 lines

  1. /* whatchar.c  --  demonstrates the character         */
  2. /*                 classification routines in ctype.h */
  3.  
  4. #include <stdio.h>        /* for NULL and BUFSIZ */
  5. #include <ctype.h>        /* for iscntl(), et al */
  6. #define MAXL 20
  7.  
  8. main()
  9. {
  10.     char buf[BUFSIZ];
  11.     int i;
  12.  
  13.     printf("Enter a line of text (20 chars max):\n");
  14.     if (gets(buf) == NULL)
  15.         exit(1);
  16.  
  17.     for (i = 0; i < MAXL; ++i)
  18.         {
  19.         if (buf[i] == '\0')
  20.             break;
  21.         printf("'%c' ->", buf[i]);
  22.         if (isalpha(buf[i]))   printf(" isalpha");
  23.         if (isascii(buf[i]))   printf(" isascii");
  24.         if (iscntrl(buf[i]))   printf(" iscntrl");
  25.         if (isgraph(buf[i]))   printf(" isgraph");
  26.         if (isprint(buf[i]))   printf(" isprint");
  27.         if (isdigit(buf[i]))   printf(" isdigit");
  28.         if (isupper(buf[i]))   printf(" isupper");
  29.         if (islower(buf[i]))   printf(" islower");
  30.         if (ispunct(buf[i]))   printf(" ispunct");
  31.         if (isspace(buf[i]))   printf(" isspace");
  32.         if (isalnum(buf[i]))   printf(" isalnum");
  33.         if (isxdigit(buf[i]))  printf(" isxdigit");
  34.         printf("\n");
  35.         }
  36. }
  37.