home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / croutes.zip / CHOSIT.C < prev    next >
Text File  |  1984-05-11  |  2KB  |  64 lines

  1. /*                              *** chosit.c ***                     */
  2. /*                                                                   */
  3. /* IBM - PC microsoft "C"                                            */
  4. /*                                                                   */
  5. /* Function to display a menu, prompt for a response, and validate.  */
  6. /* Calls function mencon to display the menu.  Returns the integer   */
  7. /* response, or -1 if invalid response or error occured.              */
  8. /*                                                                   */
  9. /* Written by L. Cuthbertson, April 1984.                            */
  10. /*                                                                   */
  11. /*********************************************************************/
  12. /*                                                                   */
  13.  
  14. int chosit(menu,ans,lenans)
  15. char menu[],ans[];
  16. int lenans;
  17. {
  18.     extern int rc[][2];
  19.     extern int vrange[2];
  20.     int i,j,ians,nfield;
  21.  
  22.     /* display menu */
  23.     if (strcmp(menu,"skip") != 0) {
  24.         nfield = mencon(menu);
  25.         if (nfield == (-1))
  26.             return(-1);    /* error in mencon */
  27.     }
  28.  
  29.     /* move cursor to entry position */
  30.     i=0;            /* position within rc array */
  31.     if (i > (nfield-1)) {
  32.         return(-1);    /* no entry position on menu */
  33.     }
  34.  
  35.     loop:
  36.     cursor(rc[i][0],rc[i][1]);
  37.  
  38.     /* accept answer */
  39.     reads(ans,lenans);
  40.  
  41.     /* convert answer to integer */
  42.     sscanf(ans,"%d",&ians);
  43.  
  44.     /* always exit if 99 entered */
  45.     if (ians == 99)
  46.         exit();
  47.  
  48.     /* validate answer */
  49.     if ((ians < vrange[0]) || (ians > vrange[1])) {
  50.         cursor(25,19);
  51.         writes("\007*** invalid response - please try again ***");
  52.         pause(5.);
  53.         cursor(25,19);
  54.         eline(0);
  55.         cursor(rc[i][0],rc[i][1]);
  56.         for (j=1;j<lenans;j++)
  57.             writec(' ');
  58.         goto loop;
  59.     }
  60.  
  61.     /* done */
  62.     return(ians);
  63. }
  64.