home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0000 - 0009 / ibm0000-0009 / ibm0003.tar / ibm0003 / LCNOW2.ZIP / EXAMPLES / CMD3.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-07-25  |  903 b   |  50 lines

  1. /*
  2.  * C M D 3
  3.  *
  4.  * Get a command from the user and take the requested action.
  5.  * This version demonstrates the use of an infinite loop.
  6.  */
  7.  
  8. main()
  9. {
  10.     int key;
  11.  
  12.     /*
  13.      * Loop until the user types the command to quit.
  14.      */
  15.     printf("Press ? for help.\n");
  16.     while (1) {
  17.         /*
  18.          * Get a command from the user.
  19.          */
  20.         printf("Command: ");
  21.         key = getch();  /* console input */
  22.  
  23.         /*
  24.          * Analyze and act on the command.
  25.          */
  26.         switch (key) {
  27.         case 'q':
  28.         case 'Q':
  29.             puts("Done.");
  30.             return (0);
  31.         case 'h':
  32.         case 'H':
  33.         case '?':
  34.             puts("CMD3 understands these commands:");
  35.             puts("h or H or ?: help frame");
  36.             puts("m or M: message");
  37.             puts("q or Q: quit");
  38.             break;
  39.         case 'm':
  40.         case 'M':
  41.             puts("Here's the message.");
  42.             puts("Pretty disappointing, huh!");
  43.             break;
  44.         default:
  45.             printf("Unknown command -- %c\n", key);
  46.             break;
  47.         }
  48.     }
  49. }
  50.