From 8dad42e7d4f17ee1a1449c4aab775d61b4544458 Mon Sep 17 00:00:00 2001 From: Ariadna Vigo Date: Sun, 9 Aug 2020 19:51:48 +0200 Subject: stdin input chomped in a better way --- cras.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cras.c b/cras.c index 7e63212..562ae0b 100644 --- a/cras.c +++ b/cras.c @@ -93,7 +93,6 @@ print_task(Task task, int i) printf("%s\n", task.tdesc); } - static void print_short_output(TaskLst list) { @@ -176,7 +175,10 @@ store_input(TaskLst *list, FILE *fp) if (fgets(linebuf, TASK_LST_DESC_MAX_SIZE, fp) == NULL) break; - linebuf[strlen(linebuf) - 1] = '\0'; /* Chomp '\n' */ + /* Chomp '\n' */ + if (linebuf[strlen(linebuf) - 1] == '\n') + linebuf[strlen(linebuf) - 1] = '\0'; + if (task_lst_add_task(list, TASK_TODO, linebuf) < 0) return -1; } -- cgit v1.2.3