summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-04-19 23:32:15 +0200
committerOskar <[email protected]>2024-04-19 23:32:15 +0200
commite0e28a119e7a0f83ef9382413dba603ae342a8fb (patch)
tree1a0a7a60cee9efbbd38ed0fc63cbd057592cf24c
parent73b0414254e6b888656b4e5346292f27b67ac9d9 (diff)
adding modes to choice
-rw-r--r--7ed.h4
-rw-r--r--TODO1
-rw-r--r--functions.c37
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 <string.h>
#include <stdint.h>
-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;