home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / i18nv104.zip / SAMPLE / IS / IS.C < prev    next >
C/C++ Source or Header  |  1996-02-13  |  4KB  |  84 lines

  1. /*****************************************************************************/
  2. /***     Include files                                                     ***/
  3. /*****************************************************************************/
  4.  
  5. #include <stdio.h>                      /* Standard IO functions.            */
  6.  
  7. #include <wchar.h>                      /* XPG/4 library.                    */
  8. #include <locale.h>                     /* Locale definitions.               */
  9.  
  10. /*****************************************************************************/
  11. /***     Global defines                                                    ***/
  12. /*****************************************************************************/
  13.  
  14. #define UPPER_LIMIT    0xFF             /* Maximum character to check.       */
  15.  
  16. /*****************************************************************************/
  17. /***     Is functions for characters                                       ***/
  18. /*****************************************************************************/
  19.  
  20. void do_is_functions(void)
  21. {
  22.   int ch;                               /* Character to check.               */
  23.  
  24.                                         /* Print out the current locale.     */
  25.   printf("The current locale is: %s\n\n", setlocale(LC_CTYPE, NULL));
  26.  
  27.                                         /* Print a header banner.            */
  28.                                         /* For each character print the      */
  29.                                         /*  following information:           */
  30.                                         /*                                   */
  31.                                         /*  1) The char number (integer).    */
  32.                                         /*  2) The hex value of the number.  */
  33.                                         /*  3) The character (if printable). */
  34.                                         /*  4) Is it alphanumeric?           */
  35.                                         /*  5) Is it alphabetic?             */
  36.                                         /*  6) Is it a control character?    */
  37.                                         /*  7) Is it a digit?                */
  38.                                         /*  8) Is it a graph character?      */
  39.                                         /*  9) Is it lowercase?              */
  40.                                         /* 10) Is it a punctuation character?*/
  41.                                         /* 11) Is it a space character?      */
  42.                                         /* 12) Is it uppercase?              */
  43.                                         /* 13) Is it a hex digit? (0-9, A-F) */
  44.   printf("Char  Hex   Char  Alpha  Alpha  Cont  Dig  Graph Lower  ");
  45.   printf("Punct  Space  Upper  Hex\n");
  46.   printf("Num   Val         numer         Char                    ");
  47.   printf("                     Dig\n");
  48.   printf("--------------------------------------------------------");
  49.   printf("------------------------");
  50.  
  51.                                         /* For each character...             */
  52.                                         /* Print out the information using   */
  53.                                         /*  the proper "is" function.        */
  54.   for (ch = 0; ch <= UPPER_LIMIT; ++ch)
  55.   {
  56.     printf("\n%-5d ", ch);
  57.     printf("%#04x ", ch);
  58.     printf(" %c     ",  isprint(ch)  ? ch   : ' ');
  59.     printf("%-6s ", isalnum(ch)  ? "YES" : "NO");
  60.     printf("%-6s ", isalpha(ch)  ? "YES"  : "NO");
  61.     printf("%-6s",  iscntrl(ch)  ? "YES"  : "NO");
  62.     printf("%-5s",  isdigit(ch)  ? "YES"  : "NO");
  63.     printf("%-6s",  isgraph(ch)  ? "YES"  : "NO");
  64.     printf("%-7s",  islower(ch)  ? "YES"  : "NO");
  65.     printf("%-7s",  ispunct(ch)  ? "YES" : "NO");
  66.     printf("%-8s",  isspace(ch)  ? "YES"  : "NO");
  67.     printf("%-6s",  isupper(ch)  ? "YES"  : "NO");
  68.     printf("%-6s",  isxdigit(ch) ? "YES"  : "NO");
  69.   }
  70. }
  71.  
  72. /*****************************************************************************/
  73. /***     Main program                                                      ***/
  74. /*****************************************************************************/
  75.  
  76. void main(void)
  77. {
  78.                                         /* Set the locale based on env var.  */
  79.   setlocale(LC_ALL, "");
  80.  
  81.                                         /* Print out the character table.    */
  82.   do_is_functions();
  83. }
  84.