aboutsummaryrefslogtreecommitdiff
path: root/src/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/input.c')
-rw-r--r--src/input.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/input.c b/src/input.c
new file mode 100644
index 0000000..9ac68be
--- /dev/null
+++ b/src/input.c
@@ -0,0 +1,33 @@
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "input.h"
+
+int prompt_yes_no(void)
+{
+ puts(" [Y/n]");
+ fflush(stdout);
+ size_t line_size = 3;
+ char *line = malloc(line_size);
+ int attempts = 0;
+ do {
+ getline(&line, &line_size, stdin);
+ char input = line[0];
+ if (input == '\n'/*no input*/ || input == 'y' || input == 'Y')
+ return 1;
+ else if (input == 'n' || input == 'N')
+ return 0;
+ attempts++;
+ }
+ while(attempts < 3);
+ return 0;
+}
+
+void remove_ending_newline(char *str)
+{
+ int idx = strlen(str) - 1;
+ assert(str[idx] == '\n');
+ str[idx] = '\0';
+}