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

  1. /* choose.c   --  an array of pointers to functions   */
  2. /*                used to create a menu               */
  3.  
  4. void Choice1(), Choice2(), Choice3();
  5.  
  6. void (*Dochoice[3])() = {Choice1, Choice2, Choice3};
  7.  
  8. main()
  9.     {
  10.     int ch;
  11.  
  12.     printf("Select 1, 2 or 3: ");
  13.     ch = getch(); putch(ch);
  14.     ch -= '1';
  15.     if (ch < 0 || ch > 2)
  16.         printf("\nNo such choice.\n");
  17.     else
  18.         Dochoice[ch]();
  19.  
  20. }
  21.  
  22. void Choice1(void) 
  23. {
  24.         printf("\nThis is choice 1\n");
  25. }
  26.  
  27. void Choice2(void) 
  28. {
  29.         printf("\nThis is choice 2\n");
  30. }
  31.  
  32. void Choice3(void) 
  33. {
  34.         printf("\nThis is choice 3\n");
  35. }
  36.