diff options
| -rw-r--r-- | src/input.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/input.c b/src/input.c index 65ec3a7..94777bb 100644 --- a/src/input.c +++ b/src/input.c @@ -10,18 +10,25 @@ int prompt_yes_no(void) { - char *line; + char *line = NULL; int attempts = 0; + int ret = 0; do { line = readline(" [Y/n] "); char input = line[0]; - if (input == '\n'/*no input*/ || input == 'y' || input == 'Y') - return 1; - else if (input == 'n' || input == 'N') - return 0; + if (input == '\n'/*no input*/ || input == 'y' || input == 'Y') { + ret = 1; + break; + } + else if (input == 'n' || input == 'N') { + break; + } attempts++; } while(attempts < 3); - return 0; + if (line != NULL) { + free(line); + } + return ret; } void remove_ending_newline(char *str) |
