home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_02 / 2n02036a < prev    next >
Text File  |  1991-01-01  |  2KB  |  76 lines

  1.  
  2. /*
  3.         Compiler:    Turbo C 2.0 Small Memory Model;
  4.     Requires:    chartab.obj;
  5.     Warning:    Compile with default char type = unsigned
  6.             and alignment = word;
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11.  
  12. extern char up_case[256], low_case[256];
  13. extern char *str2upper(char *dest, char *source);
  14. extern char *str2lower(char *dest, char *source);
  15.  
  16. #define up_string(dest,source) {\
  17. unsigned zz,z=0;\
  18. do{\
  19. zz=source[z];\
  20. dest[z++]=up_case[zz];\
  21. }while(zz);\
  22. }
  23.  
  24. #define low_string(dest,source) {\
  25. unsigned zz,z=0;\
  26. do{\
  27. zz=source[z];\
  28. dest[z++]=low_case[zz];\
  29. }while(zz);\
  30. }
  31.  
  32.  
  33. char  outstring[BUFSIZ], instring[BUFSIZ] = "iS ThIs MiXeD CaSe?";
  34.  
  35. void main(void)
  36. {
  37.     int i, j, k = 0;
  38.  
  39.     printf("\n");
  40.  
  41.     /*
  42.      *  print alpha portions of tables and check
  43.      *  non-alpha portions in tables for errors
  44.      */
  45.     for(i = 0;i < 16;i++)  {
  46.     printf("\n");
  47.  
  48.     for(j = 0;j < 15;j++)  {
  49.         if((k >= 'A' && k <= 'Z') || (k >= 'a' && k <= 'z'))
  50.         printf("%c %c ", up_case[k], low_case[k]);
  51.         else if(k != up_case[k]  || k != low_case[k])
  52.         printf("\n\n\tError in a char tabel at pos %d\n\n", k);
  53.  
  54.         ++k;
  55.     }
  56.     }
  57.  
  58.     /*
  59.      *  try conversion functions
  60.      */
  61.     printf("\n");
  62.     printf("%s\n", strcpy(outstring, instring));
  63.     printf("%s\n", str2lower(outstring, instring));
  64.     printf("%s\n", str2upper(outstring, instring));
  65.     printf("%s\n", strcpy(outstring, instring));
  66.     printf("%s\n", str2lower(outstring, outstring)); /* try in-place conv */
  67.  
  68.     /*
  69.      *  try conversion Macros
  70.      */
  71.     up_string(outstring,instring);
  72.     printf("%s\n", outstring);
  73.     low_string(outstring,instring);
  74.     printf("%s\n", outstring);
  75. }
  76.