modified: src/db.c

bugfix
ketrptr 2024-12-16 11:10:49 +01:00
parent 1f54110aa5
commit d794d1c59c
1 changed files with 9 additions and 6 deletions

View File

@ -59,11 +59,14 @@ llist *write_csv_to_llist(const char *filename) {
fprintf(stderr, "Could not open file %s\n", filename); fprintf(stderr, "Could not open file %s\n", filename);
} else { } else {
char line[1024]; // Line Buffer char *line = NULL; // Line Buffer
int count = 0; // task counter size_t nnread, len;
fgets(line, sizeof(line), file); // read and ignore file head 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++; count++;
// remove newline sign // remove newline sign
line[strcspn(line, "\n")] = '\0'; line[strcspn(line, "\n")] = '\0';
@ -74,7 +77,7 @@ llist *write_csv_to_llist(const char *filename) {
char *taskdeadline_dateSTR = strtok(NULL, ","); char *taskdeadline_dateSTR = strtok(NULL, ",");
char *taskprioritySTR = strtok(NULL, ","); char *taskprioritySTR = strtok(NULL, ",");
char *taskspareSTR = 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 // convert char in integer and date
unsigned long int taskcreation_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 // Append the task to the linked list
llistAppend(list, task); llistAppend(list, task);
} }
line = NULL;
} }
fclose(file); fclose(file);
} }
return list; // null on error return list; // null on error
} }