home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************
- *
- * NAME: askyn.c
- *
- * DESCRIPTION: ask user a y/n question
- *
- * M O D I F I C A T I O N H I S T O R Y
- *
- * when who what
- * -------------------------------------------------------------------
- * 04/09/90 J.A.Eldridge created
- *
- *********************************************************************/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdarg.h>
- #include <string.h>
-
- int
- getyn(int ctl_c)
- {
- int c;
-
- do {
- c = getch();
- c = tolower(c);
- if (c == 3 && ctl_c) {
- /*
- give the user a cheap thrill and let
- him/her think they got away with something
- */
- fputs("^C\n", stderr);
- exit(1);
- }
- } while (c != 'y' && c != 'n');
- fprintf(stderr, "%c\n", c);
- return c == 'y';
- }
-
- int
- askyn(
- int ctl_c,
- char *fmt,
- ...)
- {
- char ques[200];
- va_list ap;
-
- va_start(ap, fmt);
- vsprintf(ques, fmt, ap);
- va_end(ap);
- fprintf(stderr, "%s (y/n)? ", ques);
- return getyn(ctl_c);
- }
-