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

  1. /* rekey.c -- transliterates typed input             */
  2. /*    This program illustrates getch() and putch().  */
  3.  
  4. #include <stdio.h>
  5. #include <conio.h>
  6. #include <ctype.h>
  7. #define ESC '\033'   /* the escape key */
  8. char Newchars[] = "qwertyuiopasdfghjklzxcvbnm";
  9.  /* values to be assigned to the a,b,c keys, etc. */
  10. main()
  11. {
  12.     char ch;
  13.  
  14.     printf("Type characters and see them transformed;\n");
  15.     printf("Press the Esc key to terminate.\n");
  16.     while ((ch = getch()) != ESC)
  17.         if (islower(ch))
  18.             putch(Newchars[ch - 'a']);
  19.         else if (isupper(ch))
  20.             {
  21.             ch = tolower(ch);
  22.             putch(toupper(Newchars[ch - 'a']));
  23.             }
  24.         else if (ch == '\r')
  25.             {
  26.             putch('\n');
  27.             putch('\r');
  28.             }
  29.         else
  30.             putch(ch);
  31. }
  32.