home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc_prog / chap09 / invert.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-06  |  766 b   |  30 lines

  1. /* invert.c  --  combines character classification and */
  2. /*               transformation to invert text         */
  3.  
  4. #include <stdio.h>         /* for NULL           */
  5. #include <ctype.h>         /* for toupper, et al */
  6.  
  7. main()
  8. {
  9.     char buf[BUFSIZ];
  10.     int i;
  11.  
  12.     printf("Type in a line of text and I will invert it.\n");
  13.  
  14.     if (gets(buf) == NULL)
  15.         exit(1);
  16.  
  17.     /* Print the string backwards. */
  18.     for (i = (strlen(buf) -1); i >= 0; --i)
  19.         {
  20.         if (isupper(buf[i]))            /* upper to lower */
  21.             putchar(tolower(buf[i]));
  22.         else if (islower(buf[i]))       /* lower to upper */
  23.             putchar(toupper(buf[i]));
  24.         else
  25.             putchar(buf[i]);
  26.         }
  27.     putchar('\n');
  28.  
  29. }
  30.