home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / learn / is.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-28  |  2.0 KB  |  57 lines

  1. /* IS.C illustrates character classification functions including:
  2.  *      isprint         isascii         isalpha         isalnum
  3.  *      isupper         islower         isdigit         isxdigit
  4.  *      ispunct         isspace         iscntrl         isgraph
  5.  *
  6.  * Console output is also shown using:
  7.  *      cprintf
  8.  *
  9.  * See PRINTF.C for additional examples of formatting for cprintf.
  10.  */
  11.  
  12. #include <ctype.h>
  13. #include <conio.h>
  14.  
  15. main()
  16. {
  17.     int ch;
  18.  
  19.     /* Display each ASCII character with character type table. */
  20.     for( ch = 0; ch < 256; ch++ )
  21.     {
  22.         if( ch % 22 == 0 )
  23.         {
  24.             if( ch )
  25.                 getch();
  26.  
  27.             /* Note that cprintf does not convert "\n" to a CR/LF sequence.
  28.              * You can specify this sequence with "\n\r".
  29.              */
  30.             cprintf( "\n\rNum Char ASCII Alpha AlNum Cap Low Digit " );
  31.             cprintf( "XDigit Punct White CTRL Graph Print \n\r" );
  32.         }
  33.         cprintf( "%3d  ", ch );
  34.  
  35.         /* Console output functions (cprint, cputs, and putch) display
  36.          * graphic characters for all values except 7 (bell), 8 (backspace),
  37.          * 10 (line feed), 13 (carriage return), and 255.
  38.          */
  39.         if( ch == 7 || ch == 8 || ch == 10 || ch == 13 || ch == 255 )
  40.             cprintf("NV" );
  41.         else
  42.             cprintf("%c ", ch );
  43.         cprintf( "%5s", isascii( ch )  ? "Y" : "N" );
  44.         cprintf( "%6s", isalpha( ch )  ? "Y" : "N" );
  45.         cprintf( "%6s", isalnum( ch )  ? "Y" : "N" );
  46.         cprintf( "%5s", isupper( ch )  ? "Y" : "N" );
  47.         cprintf( "%4s", islower( ch )  ? "Y" : "N" );
  48.         cprintf( "%5s", isdigit( ch )  ? "Y" : "N" );
  49.         cprintf( "%7s", isxdigit( ch ) ? "Y" : "N" );
  50.         cprintf( "%6s", ispunct( ch )  ? "Y" : "N" );
  51.         cprintf( "%6s", isspace( ch )  ? "Y" : "N" );
  52.         cprintf( "%5s", iscntrl( ch )  ? "Y" : "N" );
  53.         cprintf( "%6s", isprint( ch )  ? "Y" : "N" );
  54.         cprintf( "%6s\n\r", isgraph( ch )  ? "Y" : "N" );
  55.     }
  56. }
  57.