diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index c13e44e..c39cd37 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -18,7 +18,16 @@
-
+
+
+
diff --git a/src/db.c b/src/db.c
index c670b3f..da2725a 100644
--- a/src/db.c
+++ b/src/db.c
@@ -13,99 +13,91 @@
#include
#include
-#include
+#include
#include "planner.h"
-#include "list.h"
+#include "llist.h"
/*
write a complete linkedlist to a task csv file.
*/
-void write_linkedlist_to_csv(llist* head, const char* filename) {
- //Open file with write permision
- FILE* file = fopen(filename, "w");
- //if there is no file or a wrong file path you becom an error
- if (file == NULL) {
- perror("Could not open file %s\n", filename);
- }
- else{
- //write the file header
- fprintf(file, "TaskName, Created, Deadline, Priority, Spare\n");
+void write_linkedlist_to_csv(llist *head, const char *filename) {
+ //Open file with write permission
+ FILE *file = fopen(filename, "w");
+ //if there is no file or a wrong file path you become an error
+ if (file == NULL) {
+ perror("Could not open file\n");
+ }
- // Iterate through the linked list and write the data to the CSV
- llist* current = head;
- while (current != NULL) {
+ //write the file header
+ fprintf(file, "TaskName, Created, Deadline, Priority, Spare\n");
- // Write the task data to the CSV file
- fprintf(file, "%s, %lu, %lu, %d, %lu\n",
- task->name,
- task->created,
- task->deadline,
- task->priority,
- task->spare,
+ // Iterate through the linked list and write the data to the CSV
+ llist *current = head;
+ while (current != NULL) {
+ // Write the task data to the CSV file
+ Task *task = (Task *) (current->data);
+ fprintf(file, "%s, %lu, %lu, %d, %lu\n",
+ task->name,
+ task->created,
+ task->deadline,
+ task->priority,
+ task->spare);
- current = current->next;
- }
- fclose(file); // Close the file
- }
+ current = current->next;
+ }
+ fclose(file); // Close the file
}
+
/*
read a task csv file and write the data in a linked list
*/
-void write_csv_to_llist(const char* filename) {
- //Open file with read permision
- FILE* file = fopen(filename, "r");
- if (file == NULL) {
- perror("Could not open file %s\n", filename);
- }
- else{
- char line[1024]; //Line Buffer
+llist *write_csv_to_llist(const char *filename) {
+ //initialize list
+ llist *list = NULL;
+ //Open file with read permission
+ FILE *file = fopen(filename, "r");
+ if (file == NULL) {
+ perror("Could not open file\n");
+ }
+ char line[1024]; //Line Buffer
int count = 0; //task counter
- llist *list = NULL
fgets(line, sizeof(line), file); //read and ignore file head
while (fgets(line, sizeof(line), file)) {
- count++;
- //remove newline sign
+ count++;
+ //remove newline sign
line[strcspn(line, "\n")] = '\0';
// column slice
- char *taskname = strtok(line, ",");
- char *tsakcreation_dateSTR = strtok(NULL, ",");
- char *tsakdeadline_dateSTR = strtok(NULL, ",");
- char *tsakprioritySTR = strtok(NULL, ",");
- char *tsakspareSTR = strtok(NULL, ",");
+ char *task_name = strtok(line, ",");
+ char *task_creation_dateSTR = strtok(NULL, ",");
+ char *task_deadline_dateSTR = strtok(NULL, ",");
+ char *task_prioritySTR = strtok(NULL, ",");
+ char *task_spareSTR = strtok(NULL, ",");
// convert char in integer and date
- unsigned long int taskcreation_date = strtoul(taskcreation_dateSTR,NULL,10);
- unsigned long int taskdeadline_date = strtoul(taskdeadline_dateSTR,NULL,10);
- unsigned long int taskspare = strtoul(taskspareSTR,NULL,10);
- int priority = atoi(prioritySTR);
-
+ unsigned long int task_creation_date = strtoul(task_creation_dateSTR,NULL, 10);
+ unsigned long int task_deadline_date = strtoul(task_deadline_dateSTR,NULL, 10);
+ unsigned long int task_spare = strtoul(task_spareSTR,NULL, 10);
+ int task_priority = (int) strtol(task_prioritySTR, NULL, 10);
//create Task
- Task *task = newTask(taskname, taskcreation_date, taskdeadline_date, taskpriority, taskspare);
-
+ Task *task = newTask(task_name, task_creation_date, task_deadline_date, task_priority, task_spare);
// Insert task into the linked list
if (list == NULL) {
// If the list is empty, initialize it with the first task
list = llistNew(task, cmpTaskN);
- }
- else {
+ } else {
// Append the task to the linked list
llistAppend(list, task);
}
}
-
fclose(file);
- }
-
-
-
+ return list;
}
-