home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / HARDDISK / BADCLU.ZIP / AE.ZIP / ASKYN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-10  |  1.2 KB  |  56 lines

  1. /**********************************************************************
  2.  *  
  3.  *  NAME:           askyn.c
  4.  *  
  5.  *  DESCRIPTION:    ask user a y/n question
  6.  *  
  7.  *  M O D I F I C A T I O N   H I S T O R Y
  8.  *
  9.  *  when        who                 what
  10.  *  -------------------------------------------------------------------
  11.  *  04/09/90    J.A.Eldridge        created
  12.  *
  13.  *********************************************************************/
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <stdarg.h>
  18. #include <string.h>
  19.  
  20. int
  21. getyn(int ctl_c)
  22. {
  23.     int c;
  24.     
  25.     do {
  26.         c = getch();
  27.         c = tolower(c);
  28.         if (c == 3 && ctl_c) {
  29.             /*
  30.                 give the user a cheap thrill and let 
  31.                 him/her think they got away with something
  32.             */                            
  33.             fputs("^C\n", stderr);
  34.             exit(1);
  35.         }
  36.     } while (c != 'y' && c != 'n');
  37.     fprintf(stderr, "%c\n", c);
  38.     return c == 'y';
  39. }
  40.  
  41. int
  42. askyn(
  43.     int     ctl_c,
  44.     char    *fmt,
  45.     ...)
  46. {
  47.     char    ques[200];
  48.     va_list ap;
  49.     
  50.     va_start(ap, fmt);
  51.     vsprintf(ques, fmt, ap);
  52.     va_end(ap);
  53.     fprintf(stderr, "%s (y/n)? ", ques);
  54.     return getyn(ctl_c);
  55. }
  56.