From d794d1c59c92a0a140c552c1889b065ae41beb80 Mon Sep 17 00:00:00 2001 From: ketrptr Date: Mon, 16 Dec 2024 11:10:49 +0100 Subject: [PATCH] modified: src/db.c --- src/db.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/db.c b/src/db.c index a2c552e..5a4ce36 100644 --- a/src/db.c +++ b/src/db.c @@ -59,11 +59,14 @@ llist *write_csv_to_llist(const char *filename) { fprintf(stderr, "Could not open file %s\n", filename); } else { - char line[1024]; // Line Buffer - int count = 0; // task counter - fgets(line, sizeof(line), file); // read and ignore file head + char *line = NULL; // Line Buffer + size_t nnread, len; + int count = 0; // task counter + getline(&line, &len, file); + free(line); + line = NULL; - while (fgets(line, sizeof(line), file)){ + while ((nnread = getline(&line, &len, file)) != -1) { count++; // remove newline sign line[strcspn(line, "\n")] = '\0'; @@ -74,7 +77,7 @@ llist *write_csv_to_llist(const char *filename) { char *taskdeadline_dateSTR = strtok(NULL, ","); char *taskprioritySTR = strtok(NULL, ","); char *taskspareSTR = strtok(NULL, ","); - printf(" Der Name des Task ist %s\n",taskname); + printf(" Der Name des Task ist %s\n", taskname); // convert char in integer and date unsigned long int taskcreation_date = @@ -96,9 +99,9 @@ llist *write_csv_to_llist(const char *filename) { // Append the task to the linked list llistAppend(list, task); } + line = NULL; } fclose(file); } return list; // null on error } -