home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / i18nv102.zip / SAMPLE / ULCASE / UL.C < prev    next >
C/C++ Source or Header  |  1995-08-28  |  3KB  |  63 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. /***     Case conversions for characters.                                  ***/
  18. /*****************************************************************************/
  19.  
  20. void do_case_functions(void)
  21. {
  22.   int ch;                               /* Character to check.               */
  23.  
  24.                                         /* Print out the current locale name.*/
  25.   printf("The current locale is: %s\n\n", setlocale(LC_CTYPE, NULL));
  26.  
  27.                                         /* Print a banner.                   */
  28.   printf("Table of case conversions for characters:\n");
  29.   printf("-----------------------------------------\n");
  30.  
  31.                                         /* For each character...             */
  32.                                         /*  If the character is alpha...     */
  33.                                         /*   If the character can be         */
  34.                                         /*    converted to lowercase,        */
  35.                                         /*    print it out.                  */
  36.                                         /*   If the character can be         */
  37.                                         /*    converted to uppercase,        */
  38.                                         /*    print it out.                  */
  39.   for (ch = 0; ch <= UPPER_LIMIT; ++ch)
  40.   {
  41.     if (isalpha(ch))
  42.     {
  43.        if (tolower(ch) != ch)
  44.           printf("'%c' converted to lowercase is: '%c'\n", ch, tolower(ch));
  45.        if (toupper(ch) != ch)
  46.           printf("'%c' converted to uppercase is: '%c'\n", ch, toupper(ch));
  47.     }
  48.   }
  49. }
  50.  
  51. /*****************************************************************************/
  52. /***     Main program                                                      ***/
  53. /*****************************************************************************/
  54.  
  55. void main(void)
  56. {
  57.                                         /* Set the locale based on env var.  */
  58.   setlocale(LC_ALL, "");
  59.  
  60.                                         /* Print out upper/lower case table. */
  61.   do_case_functions();
  62. }
  63.