home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / STRUPR.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  1KB  |  64 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  Portable, public domain replacements for strupr() & strlwr() by Bob Stout
  5. */
  6.  
  7. #include <ctype.h>
  8. #include "snip_str.h"
  9.  
  10. #if defined(__cplusplus) && __cplusplus
  11.  extern "C" {
  12. #endif
  13.  
  14. char *strupr(char *string)
  15. {
  16.       char *s;
  17.  
  18.       if (string)
  19.       {
  20.             for (s = string; *s; ++s)
  21.                   *s = toupper(*s);
  22.       }
  23.       return string;
  24.  
  25. char *strlwr(char *string)
  26. {
  27.       char *s;
  28.  
  29.       if (string)
  30.       {
  31.             for (s = string; *s; ++s)
  32.                   *s = tolower(*s);
  33.       }
  34.       return string;
  35. }
  36.  
  37. #if defined(__cplusplus) && __cplusplus
  38.  }
  39. #endif
  40.  
  41. #ifdef TEST
  42.  
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45.  
  46. main(int argc, char *argv[])
  47. {
  48.       if (argc < 2)
  49.       {
  50.             puts("Usage: STRUPR string1 [...string2 [...stringN]]");
  51.             return EXIT_FAILURE;
  52.       }
  53.       while (--argc)
  54.       {
  55.             printf("Original = \"%s\"\n", *++argv);
  56.             printf("strupr() = \"%s\"\n", strupr(*argv));
  57.             printf("strlwr() = \"%s\"\n", strlwr(*argv));
  58.       }
  59.       return EXIT_SUCCESS;
  60. }
  61.  
  62. #endif /* TEST */
  63.