diff --git a/src/ui.c b/src/ui.c index 9a032b3..38dac4d 100644 --- a/src/ui.c +++ b/src/ui.c @@ -3,3 +3,143 @@ * */ #include "planner.h" // for subject and event structs +#include +#include +#include "ui.h" + +typedef struct task_elements { + char name; + int priority; + struct task *nextTask; +}; +typedef struct task task_1; +typedef struct task* task_ptr; +task_ptr firsttask = NULL; + +typedef struct time_elements { + 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 eigneben: "); + 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; + } + +int main(void) +{ + 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- Planer beenden\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; + } + }while (choice != 4); + return EXIT_SUCCESS; +} + + + + diff --git a/src/ui.h b/src/ui.h index 8183b1f..750e9bf 100644 --- a/src/ui.h +++ b/src/ui.h @@ -1,4 +1,13 @@ #ifndef UI #define UI + +typedef struct task_elements{ + char name; + int priority; +}; +typedef struct time{ + int time; +}; + #endif // !UI