diff --git a/src/main.c b/src/main.c index d8bd498..d3f359b 100644 --- a/src/main.c +++ b/src/main.c @@ -15,7 +15,7 @@ int main(void) { } // Display characters - nmsexec(input); + nmsexec(input, NULL); // Don't forget to free the allocated memory! free(input); diff --git a/src/nms.c b/src/nms.c index aa3cf2a..0866239 100644 --- a/src/nms.c +++ b/src/nms.c @@ -44,10 +44,17 @@ char getMaskChar(void); * void nmsexec(char *) * * DESCR: - * Displays the characters stored in the / char * / parameter + * Displays the characters stored in the / char * / parameter. + * + * ARGS: + * char *src - characters to display + * char *returnOptions - user must press key in one of the characters contained in this array + * before execution will continue after /char *src/ is revealed. All + * other keyboard selections will be ignored. Most commonly used when + * displaying a menu. * */ -char nmsexec(char *src) { +char nmsexec(char *src, char *returnOptions) { struct winpos *list_pointer = NULL; struct winpos *start; // Always points to start of list struct winpos *temp; // Used for free()ing the list @@ -222,11 +229,15 @@ char nmsexec(char *src) { flushinp(); // If stdin is set to the keyboard, user must press a key to continue - if (isatty(STDIN_FILENO)) + if (isatty(STDIN_FILENO)) { ret = getch(); - else + if (returnOptions != NULL && strlen(returnOptions) > 0) + while (index(returnOptions, ret) == NULL) + ret = getch(); + } else sleep(2); + // End curses mode endwin(); diff --git a/src/nms.h b/src/nms.h index 5351177..cbf83a5 100644 --- a/src/nms.h +++ b/src/nms.h @@ -4,6 +4,6 @@ // Function prototypes // Display the characters stored in the display queue -char nmsexec(char *); +char nmsexec(char *, char *); #endif diff --git a/src/sneakers.c b/src/sneakers.c index b610845..94c55dd 100644 --- a/src/sneakers.c +++ b/src/sneakers.c @@ -154,7 +154,7 @@ int main(void) { strcat(display, foot2Center); // Display characters - input = nmsexec(display); + input = nmsexec(display, "123456"); switch (input) { case '1':