From e0e28a119e7a0f83ef9382413dba603ae342a8fb Mon Sep 17 00:00:00 2001 From: Oskar Date: Fri, 19 Apr 2024 23:32:15 +0200 Subject: adding modes to choice --- 7ed.h | 4 ++++ TODO | 1 - functions.c | 37 ++++++++++++++++++++++++------------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/7ed.h b/7ed.h index aafdb94..0fdc737 100644 --- a/7ed.h +++ b/7ed.h @@ -15,6 +15,10 @@ #define FILE_EXISTS 0 #define FILE_NOT_FOUND 1 +#define MODE_YES 0 +#define MODE_NO 1 +#define MODE_NORMAL 2 + int count_lines_in_file(char filename[], uint64_t *lines); int count_lines_in_file_posix(char filename[], size_t *lines); diff --git a/TODO b/TODO index 33a3c80..6edd88a 100644 --- a/TODO +++ b/TODO @@ -2,6 +2,5 @@ TODO list. This is mostly so i can plan more granularly and remember small stuff This is not my overall big planning board. (1 highest prio, 10 lowest) 1 - Add some quality of life features -2 - Add a way to create a file with the program. 2 - Add a way to specify default Y or N. 2 - Make new_line and remove_line_contents more efficient. Maybe allow specifying amount of lines to add so we dont need to call the function too many times. diff --git a/functions.c b/functions.c index 84cf0cb..5b434bc 100644 --- a/functions.c +++ b/functions.c @@ -6,28 +6,39 @@ #include #include -int choice() { +int choice(uint8_t mode) { + char choice; - do { + if (mode == MODE_NORMAL) { + do { + + fputs("[Y / N] ? ", stdout); - fputs("[Y / N] ? ", stdout); + choice = getchar(); + if (choice == '\n') { continue; } - choice = getchar(); - if (choice == '\n') { continue; } + while ('\n' != getchar()); - while ('\n' != getchar()); + } while ( (choice != 'Y') && (choice != 'y') && (choice != 'N') && (choice != 'n') ); - } while ( (choice != 'Y') && (choice != 'y') && (choice != 'N') && (choice != 'n') ); + if ( (choice == 'Y') || (choice == 'y') ) + { + return 0; + } - if ( (choice == 'Y') || (choice == 'y') ) - { - return 0; + if ((choice == 'N') || (choice == 'n') ) + { + return 1; + } } - if ((choice == 'N') || (choice == 'n') ) - { - return 1; + if (mode == MODE_YES) { + + } + + if (mode == MODE_NO) { + } return EXIT_FAILURE; -- cgit v1.2.3