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

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