Compare commits

...

7 Commits

Author SHA1 Message Date
Jan Wild 81a0d68cc2
do while angepasst 2024-12-14 22:31:49 +01:00
Jan Wild 8cea008459
Merge remote-tracking branch 'origin/master' 2024-12-14 22:17:12 +01:00
Jürgen Büchel 81c62f892d changes 2024-12-14 22:14:56 +01:00
Jürgen Büchel f6cea89dd2 changes 2024-12-14 22:14:17 +01:00
simon b308dc4c95 modified: src/ui.c 2024-12-14 21:44:35 +01:00
Jürgen Büchel 834b3270b9 changes 2024-12-14 21:36:09 +01:00
Jürgen Büchel 0ef20822fd changes 2024-12-14 21:31:32 +01:00
1 changed files with 83 additions and 129 deletions

212
src/ui.c
View File

@ -8,149 +8,103 @@
#include <stdio.h>
#include <stdlib.h>
#include "ui.h"
#include "planner.h"
#include "iCal.h"
#include "db.h"
#include <assert.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 = 0;
int taskdeadline_date = 0;
int taskpriority = 0;
int taskspare = 0;
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 {
list = llistAppend(list, task); // Rückgabewert verwenden
}
int choice = 0, i = 0;
do
{
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;
dump_buffer(stdin);
switch (choice)
}while(( choice < 1 || choice > 5));
{
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;
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(" 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;
}
}