diff --git a/conf.c b/conf.c index 14f5a05..52d9b6f 100644 --- a/conf.c +++ b/conf.c @@ -44,6 +44,36 @@ void addConf(ptConf confChain, int id, char title[], char speaker[], int day, in px -> next -> next = NULL; } +void removeConf(ptConf confChain, int id) { + ptConf px = confChain; + + if (px -> next -> next == NULL) { + free(px -> next); + px -> next = NULL; + } else if (px -> id == id) { + px -> id = px -> next -> id; + strcpy(px -> title, px -> next -> title); + strcpy(px -> speaker, px -> next -> speaker); + px -> day = px -> next -> day; + px -> month = px -> next -> month; + px -> year = px -> next -> year; + + ptConf tmp = px -> next; + px -> next = px -> next -> next; + free(tmp); + } else { + while (px -> next != NULL && px -> next -> id != id) { + px = px -> next; + } + + if (px -> next -> id == id) { + ptConf tmp = px -> next; + px -> next = px -> next -> next; + free(tmp); + } + } +} + int findListenerId(ptListener listenerChain) { ptListener px = listenerChain; int max = 0; @@ -83,4 +113,34 @@ void addListener(ptListener listenerChain, int id, char name[], int age, int lev px -> next = (ptListener) malloc(sizeof(tListener)); px -> next -> next = NULL; px -> next -> prev = px; +} + +void removeListener(ptListener listenerChain, int id) { + ptListener px = listenerChain; + + if (px -> next -> next == NULL) { + free(px -> next); + px -> next = NULL; + } else if (px -> id == id) { + px -> id = px -> next -> id; + strcpy(px -> name, px -> next -> name); + px -> age = px -> next -> age; + px -> level = px -> next -> level; + + ptListener tmp = px -> next; + px -> next = px -> next -> next; + px -> next -> prev = px; + free(tmp); + } else { + while (px -> next != NULL && px -> next -> id != id) { + px = px -> next; + } + + if (px -> next -> id == id) { + ptListener tmp = px -> next; + px -> next = px -> next -> next; + px -> next -> prev = px; + free(tmp); + } + } } \ No newline at end of file diff --git a/conf.h b/conf.h index df182db..861266f 100644 --- a/conf.h +++ b/conf.h @@ -42,8 +42,10 @@ typedef tListenerList* ptListenerList; int findConfId(ptConf confChain); ptConf newConfChain(); void addConf(ptConf confChain, int id, char title[], char speaker[], int day, int month, int year); +void removeConf(ptConf confChain, int id); int findListenerId(ptListener listenerChain); ptListener newListenerChain(); void addListener(ptListener listenerChain, int id, char name[], int age, int level); +void removeListener(ptListener listenerChain, int id); #endif // CONF_H diff --git a/data/confs b/data/confs index fd141d3..e69de29 100644 --- a/data/confs +++ b/data/confs @@ -1,10 +0,0 @@ -1,coucou mes copains,Jean-Pierre,25,12,2023 -2,coucou mes copains,Jean-Pierre,25,12,2023 -3,coucou mes copains,Jean-Pierre,25,12,2023 -4,coucou mes copains,Jean-Pierre,25,12,2023 -5,la,belle,6422476,762406370,6422132 -6,la,belle,6422476,-26872523,6422132 -7,e,e,22,7,2004 -8,Test,de,6422476,-1123880272,6422132 -9,Test,a,6422476,-2011631347,6422132 -10,test,test,1,1,1 diff --git a/data/listeners b/data/listeners index fef4bcb..d396019 100644 --- a/data/listeners +++ b/data/listeners @@ -1 +1 @@ -1,Jose,26,4 +1,jose,12,3 diff --git a/main.exe b/main.exe index 1baabea..e44e317 100644 Binary files a/main.exe and b/main.exe differ diff --git a/screenManager.c b/screenManager.c index af893a8..2c523ea 100644 --- a/screenManager.c +++ b/screenManager.c @@ -125,12 +125,23 @@ void menuConf(ptConf confChain, ptListener listenerChain) { scanf("%d", &year); addConf(confChain, id, title, speaker, day, month, year); + saveConf(confChain); menuConf(confChain, listenerChain); break; } case 3: + { + int id; + + printf("Id de la conference à supprimer : "); + scanf("%d", &id); + + removeConf(confChain, id); + saveConf(confChain); + menuConf(confChain, listenerChain); break; + } case 4: menu(confChain, listenerChain); @@ -157,11 +168,11 @@ void menuAbo(ptConf confChain, ptListener listenerChain) { ptListener py = listenerChain; while (py -> next != NULL) { - printf("name: %s\nage: %d\nlevel: %d", py -> name, py -> age, py -> level); + printf("id : %d\nname: %s\nage: %d\nlevel: %d", py -> id, py -> name, py -> age, py -> level); py = py -> next; } system("pause"); - menuConf(confChain, listenerChain); + menuAbo(confChain, listenerChain); break; case 2: @@ -178,12 +189,23 @@ void menuAbo(ptConf confChain, ptListener listenerChain) { scanf("%d", &level); addListener(listenerChain, id, name, age, level); + saveListeners(listenerChain); menuAbo(confChain, listenerChain); break; } case 3: + { + int id; + + printf("Id de l'abonné à supprimer : "); + scanf("%d", &id); + + removeListener(listenerChain, id); + saveListeners(listenerChain); + menuAbo(confChain, listenerChain); break; + } case 4: menu(confChain, listenerChain); @@ -196,10 +218,10 @@ void menuAbo(ptConf confChain, ptListener listenerChain) { void menu(ptConf confChain, ptListener listenerChain) { - char *options[] = {"1/ Gestion des conferences", "2/ Gestion des abonnes", "3/ Participer a une conference", "4/ Voir la meilleure conference", "5/ Voir la participation a une conference", "6/ Sauvegarder", "7/ Quitter"}; + char *options[] = {"1/ Gestion des conferences", "2/ Gestion des abonnes", "3/ Participer a une conference", "4/ Voir la meilleure conference", "5/ Voir la participation a une conference", "6/ Quitter"}; system("cls"); - drawMenu(options, 7); - goToCoords(0, 15); + drawMenu(options, 6); + goToCoords(0, 14); printf("Que voulez-vous faire ? : "); int choice; scanf("%d", &choice); @@ -224,9 +246,6 @@ void menu(ptConf confChain, ptListener listenerChain) break; case 6: - saveConf(confChain); - saveListeners(listenerChain); - menu(confChain, listenerChain); break; default: