home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / lib / r_la4_01 / putmenus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-12-02  |  1.4 KB  |  43 lines

  1. /* PUTMENUS.C - Program to print menus on the screen. Typed     */
  2. /* from the book "Microsoft C Programming for the IBM" by Rob-  */
  3. /* ert Lafore, page 264.                                        */
  4. /****************************************************************/
  5.  
  6. #define SIZE1 5               /* Items on menu1 */
  7. #define SIZE2 4               /* Items on menu2 */
  8. #define CLEAR "\x1B[2J"       /* Clears screen  */
  9.  
  10. main()
  11. {
  12. static char *menu1[] =        /*first menu*/
  13.             {  "Open",
  14.                "Close",
  15.                "Save",
  16.                "Print",
  17.                "Quit"   };
  18. static char *menu2[] =        /*second menu*/
  19.             {  "Cut",
  20.                "Copy",
  21.                "Paste",
  22.                "Reformat"  };
  23.    printf(CLEAR);              /*Clear screen*/
  24.    display(menu1, SIZE1, 20);    /*Display first menu*/
  25.    display(menu2, SIZE2, 40);    /*Display second menu*/
  26.    getch();
  27. }
  28.  
  29. /* display() */
  30. /* Displays menu at given column number */
  31. display(arr, size, hpos)
  32. char *arr[];                  /*array to display*/
  33. int size;                     /*size of array*/
  34. int hpos;                     /*column number*/
  35. {
  36. int j;
  37.  
  38.    for(j = 0; j < size; j++) {         /*for each menu item*/
  39.       printf("\x1B[%d;%df", j + 1, hpos);    /*position cursor*/
  40.       printf("%s\n", *(arr + j));            /*print item*/
  41.    }
  42. }
  43.