From 0ef20822fd4b579c149f5865d63fd1b1e073f4d6 Mon Sep 17 00:00:00 2001 From: juergen Date: Sat, 14 Dec 2024 21:31:32 +0100 Subject: [PATCH 1/5] changes --- src/ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui.c b/src/ui.c index 8f7bdc6..18e89a3 100644 --- a/src/ui.c +++ b/src/ui.c @@ -4,7 +4,7 @@ */ /* Created by Juergen Buechel, 13.12.2024/ */ -#include "planner.h" // for subject and event structs +#include "planner.h" // for suject and event structs #include #include #include "ui.h" From 834b3270b9c6d82751db2d84e70088b2fe828eb8 Mon Sep 17 00:00:00 2001 From: juergen Date: Sat, 14 Dec 2024 21:36:09 +0100 Subject: [PATCH 2/5] changes --- src/ui.c | 192 +++++++++++++++++++------------------------------------ 1 file changed, 66 insertions(+), 126 deletions(-) diff --git a/src/ui.c b/src/ui.c index 18e89a3..c3268a0 100644 --- a/src/ui.c +++ b/src/ui.c @@ -4,126 +4,40 @@ */ /* Created by Juergen Buechel, 13.12.2024/ */ -#include "planner.h" // for suject and event structs +#include "planner.h" // for subject and event structs #include #include #include "ui.h" + +#include + #include "planner.h" -#include "iCal.h" #include "db.h" +#include "llist.h" -typedef struct task { - char name; - int priority; - struct task *nextTask; -}; - -typedef struct task task_1; -typedef struct task* task_ptr; -task_ptr firsttask = NULL; - -typedef struct time { - int time; - struct time *nextTime; -}; - -typedef struct time time_1; -typedef struct time* time_ptr; -time_ptr firsttime = NULL; - -void dump_buffer(FILE *fp){ - int ch; - while((ch = fgetc(fp)) != EOF && ch != '\n'); -} - - -void insertTask(task_ptr newtask) -{ - task_ptr TaskPointer; - if (firsttask == NULL){ - firsttask = newtask; - newtask->nextTask ; - } - else { - TaskPointer = firsttask; - while(TaskPointer->nextTask!=NULL) - { - TaskPointer = TaskPointer->nextTask; - } - TaskPointer->nextTask = newtask; - newtask ->nextTask; - } -} - -void newTask (void) -{ - task_ptr new = malloc(sizeof(task_1)); - if (new == NULL){ - printf("Die Liste ist leer?!\n"); - } - printf(" Neues Fach eigeben: "); - if(scanf("%d", &newTask)!=1) - { - dump_buffer(stdin); - printf("Fehlerhafte eingabe\n"); - free(new); - return; - } - dump_buffer (stdin); - insertTask(new); -} - -void inserttime(time_ptr newtime) -{ - time_ptr TimePointer; - if (firsttime == NULL){ - firsttime = newtime; - newtime->nextTime =NULL; - } - else { - TimePointer = firsttime; - while(TimePointer->nextTime!=NULL) - { - TimePointer = TimePointer->nextTime; - } - TimePointer->nextTime = newtime; - newtime ->nextTime = NULL; - } -} - -void newTime(void) -{ - time_ptr newtime = malloc(sizeof(task_1)); - if (newtime == NULL){ - printf("Die Liste ist leer?!\n"); - } - printf(" Neue Zeit eingeben: "); - if(scanf("%d",&newTime)!=1) - { - dump_buffer(stdin); - printf("Fehlerhafte eingabe\n"); - free(newtime); - return; - } - dump_buffer (stdin); - inserttime(newtime); -} - -void tasklisting(void){ - task_ptr TaskPointer = firsttask; - printf("Erfasste Fächer:\n"); - while(TaskPointer!=NULL) - printf("\t->%d\n", TaskPointer->name); - TaskPointer = TaskPointer->nextTask; - } - -void getlink (void) -{ - -} int main(void) { + char taskname; + int taskcreation_date; + int taskdeadline_date; + int taskpriority; + int taskspare; + + Task *task = newTask(taskname, taskcreation_date, taskdeadline_date, taskpriority, taskspare); + { + // 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 { + // Append the task to the linked list + llistAppend(list, task); + } + } + + int time; int choice = 0, i = 0; do { @@ -132,25 +46,51 @@ int main(void) printf(" -3- Alle vorhandenen Faecher aufliesten\n"); printf(" -4- Kalenderlink ausgeben\n"); printf(" -5- Planer beenden\n"); + printf(" Wähle die gewünschte Option aus\n"); if( scanf("%d", &choice) != 1){ printf("Falsche Eingabe\n");}; choice = 0; - dump_buffer(stdin); - switch (choice) - { - case 1: newTask();break; - case 2: newTime();break; - case 3: if( firsttask == NULL){ - printf("Die Liste ist leer"); - } - else{ - tasklisting(); - }break; - case 4: iCAl();break; - } - }while (choice !=5); - return EXIT_SUCCESS; + while(( choice < 1 || choice > 5)){ + switch (choice) + { + case 1: + { + printf(" Geben sie das gewünschte Fach ein: \n"); + scanf("%c",taskname); + + printf(" Wie viel Zeit bleibt ihnen:\n") + scanf("%c", taskdeadline_date); + + printf(" Gib die Priorität des Faches an: \n"); + scanf("%c", &taskpriority); + + printf(" Wie viel Zeit habe Sie für dieses Fach: \n"); + scanf("%c", taskspare); + } + + case 2: + printf("Geben Sie die zur verfuegung stehende Zeit für die Fächer an: \n"); + scanf("%c", &taskspare); + + case 3: if( task == NULL){ + printf("Die Liste ist leer"); + } + else{ + while (task != NULL) + { + printf("Faecher %d: \n", llistAppend(task)); + + } + + }break; + // case 4: iCAl();break; + } + }while (choice !=5); + return EXIT_SUCCESS; + + +} } From b308dc4c955c2b0d969e2f9ab903d823f2717a8b Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 14 Dec 2024 21:44:35 +0100 Subject: [PATCH 3/5] modified: src/ui.c --- src/ui.c | 142 ++++++++++++++++++++++++++----------------------------- 1 file changed, 68 insertions(+), 74 deletions(-) diff --git a/src/ui.c b/src/ui.c index c3268a0..d39b46a 100644 --- a/src/ui.c +++ b/src/ui.c @@ -3,96 +3,90 @@ * */ /* Created by Juergen Buechel, 13.12.2024/ -*/ + */ +#include "ui.h" #include "planner.h" // for subject and event structs #include #include -#include "ui.h" #include -#include "planner.h" #include "db.h" #include "llist.h" +#include "planner.h" +int main(void) { + char taskname; + int taskcreation_date; + int taskdeadline_date; + int taskpriority; + int taskspare; -int main(void) -{ - char taskname; - int taskcreation_date; - int taskdeadline_date; - int taskpriority; - int taskspare; - - Task *task = newTask(taskname, taskcreation_date, taskdeadline_date, taskpriority, taskspare); - { - // 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 { - // Append the task to the linked list - llistAppend(list, task); - } + // Uninitialized Vars! values must be known and alloced first! + Task *task = newTask(taskname, taskcreation_date, taskdeadline_date, + taskpriority, taskspare); + { + // Insert task into the linked list + if (list == NULL) { // which list + // If the list is empty, initialize it with the first task + // + // task can be NULL to init llist. + // use llist->next to gitve to next function + list = llistNew(task, cmpTaskN); + } else { + // Append the task to the linked list + llistAppend(list, task); // task would be appended for 2nd time here } + } - int time; - int choice = 0, i = 0; - do - { - printf(" -1- Neues Fach eingeben\n"); - printf(" -2- Verfuegbare Zeit eingeben\n"); - printf(" -3- Alle vorhandenen Faecher aufliesten\n"); - printf(" -4- Kalenderlink ausgeben\n"); - printf(" -5- Planer beenden\n"); - printf(" Wähle die gewünschte Option aus\n"); - if( scanf("%d", &choice) != 1){ - printf("Falsche Eingabe\n");}; - choice = 0; + int time; + int choice = 0, i = 0; + do { + printf(" -1- Neues Fach eingeben\n"); + printf(" -2- Verfuegbare Zeit eingeben\n"); + printf(" -3- Alle vorhandenen Faecher aufliesten\n"); + printf(" -4- Kalenderlink ausgeben\n"); + printf(" -5- Planer beenden\n"); + printf(" Wähle die gewünschte Option aus\n"); + if (scanf("%d", &choice) != 1) { + printf("Falsche Eingabe\n"); + }; + choice = 0; - while(( choice < 1 || choice > 5)){ - switch (choice) - { - case 1: - { - printf(" Geben sie das gewünschte Fach ein: \n"); - scanf("%c",taskname); + while ((choice < 1 || choice > 5)) { + switch (choice) { + case 1: { + printf(" Geben sie das gewünschte Fach ein: \n"); + scanf("%c", taskname); // string not single char - printf(" Wie viel Zeit bleibt ihnen:\n") - scanf("%c", taskdeadline_date); + printf(" Wie viel Zeit bleibt ihnen:\n") scanf("%c", taskdeadline_date); - printf(" Gib die Priorität des Faches an: \n"); - scanf("%c", &taskpriority); + printf(" Gib die Priorität des Faches an: \n"); + scanf("%c", &taskpriority); - printf(" Wie viel Zeit habe Sie für dieses Fach: \n"); - scanf("%c", taskspare); - } - - case 2: - printf("Geben Sie die zur verfuegung stehende Zeit für die Fächer an: \n"); - scanf("%c", &taskspare); - - case 3: if( task == NULL){ - printf("Die Liste ist leer"); - } - else{ - while (task != NULL) - { - printf("Faecher %d: \n", llistAppend(task)); - - } - - }break; - // case 4: iCAl();break; - } - }while (choice !=5); - return EXIT_SUCCESS; + printf(" Wie viel Zeit habe Sie für dieses Fach: \n"); + scanf("%c", taskspare); + } + case 2: + printf( + "Geben Sie die zur verfuegung stehende Zeit für die Fächer an: \n"); + scanf("%c", &taskspare); + case 3: + if (task == NULL) { + printf("Die Liste ist leer"); + } else { + while (task != NULL) { + printf("Faecher %d: \n", llistAppend(task)); + } + } + break; + // case 4: iCAl();break; + } + } + while (choice != 5) + ; + return EXIT_SUCCESS; + } } -} - - - - From f6cea89dd273346267973326b51925ec6136dc2b Mon Sep 17 00:00:00 2001 From: juergen Date: Sat, 14 Dec 2024 22:14:17 +0100 Subject: [PATCH 4/5] changes --- src/ui.c | 160 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 91 insertions(+), 69 deletions(-) diff --git a/src/ui.c b/src/ui.c index d39b46a..77731ff 100644 --- a/src/ui.c +++ b/src/ui.c @@ -3,90 +3,112 @@ * */ /* Created by Juergen Buechel, 13.12.2024/ - */ -#include "ui.h" +*/ #include "planner.h" // for subject and event structs #include #include - +#include "ui.h" #include - #include "db.h" #include "llist.h" -#include "planner.h" -int main(void) { - char taskname; - int taskcreation_date; - int taskdeadline_date; - int taskpriority; - int taskspare; - // Uninitialized Vars! values must be known and alloced first! - Task *task = newTask(taskname, taskcreation_date, taskdeadline_date, - taskpriority, taskspare); - { - // Insert task into the linked list - if (list == NULL) { // which list - // If the list is empty, initialize it with the first task - // - // task can be NULL to init llist. - // use llist->next to gitve to next function - list = llistNew(task, cmpTaskN); +int main(void) +{ + char taskname ; + int taskcreation_date; + int taskdeadline_date = 0; + int taskpriority; + int taskspare; + llist *list = NULL; + + Task *task = newTask(taskname, taskcreation_date, taskdeadline_date, taskpriority, taskspare); + if (task == NULL) { + printf("Fehler beim Erstellen der Aufgabe.\n"); + return -1; + } + + if (list == NULL) { + list = llistNew(task, cmpTaskN); } else { - // Append the task to the linked list - llistAppend(list, task); // task would be appended for 2nd time here + list = llistAppend(list, task); // Rückgabewert verwenden } - } - int time; - int choice = 0, i = 0; - do { - printf(" -1- Neues Fach eingeben\n"); - printf(" -2- Verfuegbare Zeit eingeben\n"); - printf(" -3- Alle vorhandenen Faecher aufliesten\n"); - printf(" -4- Kalenderlink ausgeben\n"); - printf(" -5- Planer beenden\n"); - printf(" Wähle die gewünschte Option aus\n"); - if (scanf("%d", &choice) != 1) { - printf("Falsche Eingabe\n"); - }; - choice = 0; - while ((choice < 1 || choice > 5)) { - switch (choice) { - case 1: { - printf(" Geben sie das gewünschte Fach ein: \n"); - scanf("%c", taskname); // string not single char + int choice = 0, i = 0; + do + { + printf(" -1- Neues Fach eingeben\n"); + printf(" -2- Verfuegbare Zeit eingeben\n"); + printf(" -3- Alle vorhandenen Faecher aufliesten\n"); + printf(" -4- Kalenderlink ausgeben\n"); + printf(" -5- Planer beenden\n"); + printf(" Wähle die gewünschte Option aus\n"); + if( scanf("%d", &choice) != 1){ + printf("Falsche Eingabe\n");}; + choice = 0; - printf(" Wie viel Zeit bleibt ihnen:\n") scanf("%c", taskdeadline_date); + while(( choice < 1 || choice > 5)){ + switch (choice) + { + case 1: + { + printf(" Geben sie das gewünschte Fach ein: \n"); + if (scanf("%255s", taskname) != 1) { + printf("Ungültige Eingabe für den Namen.\n"); + return -1; + } - printf(" Gib die Priorität des Faches an: \n"); - scanf("%c", &taskpriority); - printf(" Wie viel Zeit habe Sie für dieses Fach: \n"); - scanf("%c", taskspare); - } + printf(" Wie viel Zeit bleibt ihnen:\n"); + if (scanf("%d", &taskdeadline_date) != 1) { + printf("Ungültige Eingabe.\n"); + return -1; + } + + + printf(" Gib die Priorität des Faches an: \n"); + if (scanf("%d", &taskpriority) != 1) { + printf("Ungültige Eingabe.\n"); + return -1; + } + + + printf(" Wie viel Zeit habe Sie für dieses Fach: \n"); + if (scanf("%d", &taskspare) != 1) { + printf("Ungültige Eingabe.\n"); + return -1; + } + break; + + case 2: + printf("Geben Sie die zur verfuegung stehende Zeit für die Fächer an: \n"); + scanf("%c", &taskspare); + break; + + case 3: if( task == NULL){ + printf("Die Liste ist leer"); + } + else + { + llist *iterator = list; + while (iterator != NULL) { + Task *currentTask = (Task *)(iterator->data); // Cast zu Task + printf("Fach: %s, Deadline: %ld, Priorität: %d\n", + currentTask->name, currentTask->deadline, currentTask->priority); + iterator = iterator->next; // Gehe zum nächsten Listenelement + } + } + break; + // case 4: iCAl();break; + } + }while (choice !=5); + return EXIT_SUCCESS; - case 2: - printf( - "Geben Sie die zur verfuegung stehende Zeit für die Fächer an: \n"); - scanf("%c", &taskspare); - case 3: - if (task == NULL) { - printf("Die Liste ist leer"); - } else { - while (task != NULL) { - printf("Faecher %d: \n", llistAppend(task)); - } - } - break; - // case 4: iCAl();break; - } - } - while (choice != 5) - ; - return EXIT_SUCCESS; - } } +} + + + + From 81c62f892dd3864d550d975e3c3f38bbdd7af9c4 Mon Sep 17 00:00:00 2001 From: juergen Date: Sat, 14 Dec 2024 22:14:56 +0100 Subject: [PATCH 5/5] changes --- src/ui.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ui.c b/src/ui.c index 77731ff..b2bab4d 100644 --- a/src/ui.c +++ b/src/ui.c @@ -16,10 +16,10 @@ int main(void) { char taskname ; - int taskcreation_date; + int taskcreation_date = 0; int taskdeadline_date = 0; - int taskpriority; - int taskspare; + int taskpriority = 0; + int taskspare = 0; llist *list = NULL; Task *task = newTask(taskname, taskcreation_date, taskdeadline_date, taskpriority, taskspare);