diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 5f320dc..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -main.exe -singleFile.exe \ No newline at end of file diff --git a/conf.c b/conf.c index 5d023ac..9278f44 100644 --- a/conf.c +++ b/conf.c @@ -91,6 +91,7 @@ ptListener newListenerChain() { listenerChain -> prev = NULL; listenerChain -> next = (ptListener) malloc(sizeof(tListener)); listenerChain -> next -> prev = listenerChain; + listenerChain -> next -> next = NULL; listenerChain -> id = -1; return listenerChain; @@ -159,20 +160,15 @@ void addConfToConfList(ptConfList confList, ptConf conf, int grade) { void removeConfFromConfList(ptConfList confList, ptConf conf) { ptConfList px = confList; - while (px -> next != NULL && px -> conf != conf) { + while (px -> next != NULL && px -> next -> conf != conf) { px = px -> next; } - printConfList(confList -> next); - printf("%d\n", px -> conf -> id); - if (px -> next != NULL && px -> next -> conf == conf) { ptConfList tmp = px -> next -> next; free(px -> next); px -> next = tmp; } - - system("pause"); } void printConfList(ptConfList confList) { @@ -202,7 +198,7 @@ void addListenerToListenerList(ptListenerList listenerList, ptListener listener, void removeListenerFromListenerList(ptListenerList listenerList, ptListener listener) { ptListenerList px = listenerList; - while (px -> next != NULL && px -> listener != listener) { + while (px -> next != NULL && px -> next -> listener != listener) { px = px -> next; } diff --git a/data/confs b/data/confs index fbe43fa..fa10f60 100644 --- a/data/confs +++ b/data/confs @@ -1,3 +1,4 @@ +1,Rapport_du_GIEC,Jean_Jouzzel,15,11,2022 2,L_esprit_critique,Thomas_Durand,6,2,2023 3,La_resilience,Arthur_Keller,20,10,2022 4,American_lobbying,Salah_Oueslati,30,11,2023 diff --git a/dataBackup/relations b/dataBackup/relations index a8edff2..423a92f 100644 --- a/dataBackup/relations +++ b/dataBackup/relations @@ -1,2 +1,5 @@ 1:12;0,1;4 +2:12;0,1;4 +3:12;0,1;4 +4:12;0,1;4 9:20;5 diff --git a/fileManager.c b/fileManager.c index e6d6088..6c81bec 100644 --- a/fileManager.c +++ b/fileManager.c @@ -94,8 +94,10 @@ void saveRelations(ptConf confChain) { FILE *file = fopen("./data/relations", "w"); ptConf px = confChain; ptListenerList py; + printf("test"); while(px -> next != NULL){ - py = px -> listeners; + printf("test"); + py = px -> listeners -> next; if (py -> next != NULL) { fprintf(file, "%d:", px -> id); diff --git a/main.exe b/main.exe new file mode 100644 index 0000000..b3053ca Binary files /dev/null and b/main.exe differ diff --git a/screenManager.c b/screenManager.c index 56ca07b..662e9fb 100644 --- a/screenManager.c +++ b/screenManager.c @@ -105,6 +105,8 @@ void menuConf(ptConf confChain, ptListener listenerChain) { system("cls"); drawMenu(options, 5); goToCoords(0, 13); + tasse(); + printf("\n"); printf("Que voulez-vous faire ? : "); int choice; scanf("%d", &choice); @@ -160,6 +162,15 @@ void menuConf(ptConf confChain, ptListener listenerChain) { case 3: { + ptConf px = confChain -> next; + + printf("\n"); + while (px -> next != NULL) { + printf("%d : %s\n", px -> id, px -> title); + px = px -> next; + } + printf("\n"); + int id; printf("Id de la conference a supprimer : "); @@ -167,6 +178,7 @@ void menuConf(ptConf confChain, ptListener listenerChain) { removeConf(confChain, id); saveConf(confChain -> next); + saveRelations(confChain -> next); menuConf(confChain, listenerChain); break; } @@ -216,6 +228,8 @@ void menuAbo(ptConf confChain, ptListener listenerChain) { system("cls"); drawMenu(options, 4); goToCoords(0, 12); + tasse(); + printf("\n"); printf("Que voulez-vous faire ? : "); int choice; scanf("%d", &choice); @@ -264,6 +278,15 @@ void menuAbo(ptConf confChain, ptListener listenerChain) { case 3: { + ptListener px = listenerChain -> next; + + printf("\n"); + while (px -> next != NULL) { + printf("%d : %s\n", px -> id, px -> name); + px = px -> next; + } + printf("\n"); + int id; printf("Id de l'abonne a supprimer : "); @@ -271,6 +294,7 @@ void menuAbo(ptConf confChain, ptListener listenerChain) { removeListener(listenerChain, id); saveListeners(listenerChain -> next); + saveRelations(confChain -> next); menuAbo(confChain, listenerChain); break; } @@ -308,6 +332,21 @@ void menu(ptConf confChain, ptListener listenerChain) case 3: { + ptConf px = confChain -> next; + ptListener py = listenerChain -> next; + + printf("\n"); + while (px -> next != NULL) { + printf("%d : %s\n", px -> id, px -> title); + px = px -> next; + } + printf("\n"); + while (py -> next != NULL) { + printf("%d : %s\n", py -> id, py -> name); + py = py -> next; + } + printf("\n"); + int confId, listenerId, grade; printf("Entrez l'ID de la conference : "); scanf("%d", &confId); @@ -317,7 +356,7 @@ void menu(ptConf confChain, ptListener listenerChain) scanf("%d", &grade); if (participateToConf(confChain, listenerChain, confId, listenerId, grade) != -1) { - saveRelations(confChain); + saveRelations(confChain -> next); } else { printf("La note doit etre comprise entre 0 et 5 et l'abonne ne doit pas avoir deja participe a la conference\n\n"); system("pause"); diff --git a/singleFile.c b/singleFile.c index 6483b3e..494561a 100644 --- a/singleFile.c +++ b/singleFile.c @@ -60,8 +60,10 @@ ptListener newListenerChain(); int addListener(ptListener listenerChain, int id, char name[], int age, int level); void removeListener(ptListener listenerChain, int id); void addConfToConfList(ptConfList confList, ptConf conf, int grade); +void removeConfFromConfList(ptConfList confList, ptConf conf); void printConfList(ptConfList confList); void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade); +void removeListenerFromListenerList(ptListenerList listenerList, ptListener listener); void printListenerList(ptListenerList listenerList); int participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade); int confGradeAvg(ptConf conf); @@ -89,7 +91,9 @@ ptConf newConfChain() { ptConf confChain = (ptConf)malloc(sizeof(tConf)); - confChain->next = NULL; + confChain->next = (ptConf)malloc(sizeof(tConf)); + confChain->next->next = NULL; + confChain->id = -1; return confChain; } @@ -110,7 +114,9 @@ void addConf(ptConf confChain, int id, char title[], char speaker[], int day, in strcpy(px->title, title); strcpy(px->speaker, speaker); px->listeners = (ptListenerList)malloc(sizeof(tListenerList)); - px->listeners->next = NULL; + px->listeners->next = (ptListenerList)malloc(sizeof(tListenerList)); + px->listeners->listener = NULL; + px->listeners->next->next = NULL; px->next = (ptConf)malloc(sizeof(tConf)); px->next->next = NULL; } @@ -119,42 +125,24 @@ void removeConf(ptConf confChain, int id) { ptConf px = confChain; - if (px->next == NULL) + while (px->next != NULL && px->next->id != id) { - return; + px = px->next; } - else if (px->next->next == NULL) - { + if (px->next != NULL && px->next->id == id) + { + ptListenerList py = px->next->listeners->next; + + while (py->next != NULL) + { + removeConfFromConfList(py->listener->confs, px->next); + py = py->next; + } + + ptConf tmp = px->next->next; free(px->next); - px->next = NULL; - } - else if (px->id == id && px->next->next != NULL) - { - 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); - } + px->next = tmp; } } @@ -181,7 +169,10 @@ ptListener newListenerChain() ptListener listenerChain = (ptListener)malloc(sizeof(tListener)); listenerChain->prev = NULL; - listenerChain->next = NULL; + listenerChain->next = (ptListener)malloc(sizeof(tListener)); + listenerChain->next->prev = listenerChain; + listenerChain->next->next = NULL; + listenerChain->id = -1; return listenerChain; } @@ -205,7 +196,9 @@ int addListener(ptListener listenerChain, int id, char name[], int age, int leve px->age = age; px->level = level; px->confs = (ptConfList)malloc(sizeof(tConfList)); - px->confs->next = NULL; + px->confs->next = (ptConfList)malloc(sizeof(tConfList)); + px->confs->conf = NULL; + px->confs->next->next = NULL; px->next = (ptListener)malloc(sizeof(tListener)); px->next->next = NULL; px->next->prev = px; @@ -215,41 +208,26 @@ int addListener(ptListener listenerChain, int id, char name[], int age, int leve void removeListener(ptListener listenerChain, int id) { ptListener px = listenerChain; - if (px->next == NULL) + + while (px->next != NULL && px->next->id != id) { - return; + px = px->next; } - else if (px->id == id && px->next->next == NULL) + + if (px->next != NULL && px->next->id == id) { + ptConfList py = px->next->confs->next; + + while (py->next != NULL) + { + removeListenerFromListenerList(py->conf->listeners, px->next); + py = py->next; + } + + ptListener tmp = px->next->next; 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 = tmp; 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); - } } } @@ -268,44 +246,20 @@ void addConfToConfList(ptConfList confList, ptConf conf, int grade) px->next->next = NULL; } -void removeConfFromConfList(ptConf confChain, ptConfList confList, ptConf conf) +void removeConfFromConfList(ptConfList confList, ptConf conf) { + ptConfList px = confList; - if (confList->next == NULL) + while (px->next != NULL && px->next->conf != conf) { - return; + px = px->next; } - else if (confList->next->next == NULL && confList->conf == conf) - { - free(confList->next); - confList->next = NULL; - } - else if (confList->conf == conf && confList->next->next != NULL) - { - confList->conf = confList->next->conf; - confList->grade = confList->next->grade; - ptConfList tmp = confList->next->next; - free(confList->next); - confList->next = tmp; - } - else - { - ptConfList px = confList; - while (px->next != NULL && px->next->conf != conf) - { - if (confChain == conf && px->conf == conf->next) { - px->conf - } - - px = px->next; - } - - if (px->next->conf == conf) { - ptConfList tmp = px->next->next; - free(px->next); - px->next = tmp; - } + if (px->next != NULL && px->next->conf == conf) + { + ptConfList tmp = px->next->next; + free(px->next); + px->next = tmp; } } @@ -313,7 +267,7 @@ void printConfList(ptConfList confList) { ptConfList px = confList; - printf(" Participation aux conferences : "); + printf("Participation aux conferences : "); while (px->next != NULL) { printf("%s(%d) ", px->conf->title, px->grade); @@ -337,11 +291,28 @@ void addListenerToListenerList(ptListenerList listenerList, ptListener listener, px->next->next = NULL; } +void removeListenerFromListenerList(ptListenerList listenerList, ptListener listener) +{ + ptListenerList px = listenerList; + + while (px->next != NULL && px->next->listener != listener) + { + px = px->next; + } + + if (px->next != NULL && px->next->listener == listener) + { + ptListenerList tmp = px->next->next; + free(px->next); + px->next = tmp; + } +} + void printListenerList(ptListenerList listenerList) { ptListenerList px = listenerList; - printf(" Participants : "); + printf("Participants : "); while (px->next != NULL) { printf("%s(%d) ", px->listener->name, px->grade); @@ -366,7 +337,7 @@ int participateToConf(ptConf confChain, ptListener listenerChain, int confId, in px = px->next; } - pz = px->listeners; + pz = px->listeners->next; while (pz->next != NULL) { if (pz->listener->id == listenerId) @@ -394,7 +365,7 @@ int participateToConf(ptConf confChain, ptListener listenerChain, int confId, in int confGradeAvg(ptConf conf) { - ptListenerList px = conf->listeners; + ptListenerList px = conf->listeners->next; int total = 0, nb = 0; while (px->next != NULL) @@ -416,7 +387,7 @@ int confGradeAvg(ptConf conf) int confParticipations(ptConf conf) { - ptListenerList px = conf->listeners; + ptListenerList px = conf->listeners->next; int nb = 0; while (px->next != NULL) @@ -545,9 +516,11 @@ void saveRelations(ptConf confChain) FILE *file = fopen("./data/relations", "w"); ptConf px = confChain; ptListenerList py; + printf("test"); while (px->next != NULL) { - py = px->listeners; + printf("test"); + py = px->listeners->next; if (py->next != NULL) { @@ -585,7 +558,6 @@ void drawMenu(char *options[], int lenght); void tasse(); void menuConf(ptConf confChain, ptListener listenerChain); void menuAbo(ptConf confChain, ptListener listenerChain); - void menu(ptConf confChain, ptListener listenerChain); void goToCoords(int x, int y) @@ -694,6 +666,8 @@ void menuConf(ptConf confChain, ptListener listenerChain) system("cls"); drawMenu(options, 5); goToCoords(0, 13); + tasse(); + printf("\n"); printf("Que voulez-vous faire ? : "); int choice; scanf("%d", &choice); @@ -702,21 +676,21 @@ void menuConf(ptConf confChain, ptListener listenerChain) { case 1: { - ptConf px = confChain; + ptConf px = confChain->next; while (px->next != NULL) { - printf(" Id : %d\n Titre : %s\n Conferencier : %s\n", px->id, px->title, px->speaker); - printf(" Date : %d/%d/%d\n", px->day, px->month, px->year); - printf(" Nombre de participants : %d\n", confParticipations(px)); + printf("Id : %d\nTitre : %s\nConferencier : %s\n", px->id, px->title, px->speaker); + printf("Date : %d/%d/%d\n", px->day, px->month, px->year); + printf("Nombre de participants : %d\n", confParticipations(px)); if (px->listeners->next != NULL) { - printListenerList(px->listeners); + printListenerList(px->listeners->next); } int avg; if ((avg = confGradeAvg(px) != -1)) { - printf(" Moyenne des notes : %d\n", confGradeAvg(px)); + printf("Moyenne des notes : %d\n", confGradeAvg(px)); } printf("\n"); px = px->next; @@ -733,32 +707,43 @@ void menuConf(ptConf confChain, ptListener listenerChain) char speaker[20]; id = findConfId(confChain); - printf(" Titre de la conference : "); + printf("Titre de la conference : "); scanf("%29s", &title); - printf(" Nom du conferencier : "); + printf("Nom du conferencier : "); scanf("%19s", &speaker); - printf(" Jour : "); + printf("Jour : "); scanf("%d", &day); - printf(" Mois : "); + printf("Mois : "); scanf("%d", &month); - printf(" Annee : "); + printf("Annee : "); scanf("%d", &year); addConf(confChain, id, title, speaker, day, month, year); - saveConf(confChain); + saveConf(confChain->next); menuConf(confChain, listenerChain); break; } case 3: { + ptConf px = confChain->next; + + printf("\n"); + while (px->next != NULL) + { + printf("%d : %s\n", px->id, px->title); + px = px->next; + } + printf("\n"); + int id; - printf(" Id de la conference a supprimer : "); + printf("Id de la conference a supprimer : "); scanf("%d", &id); removeConf(confChain, id); - saveConf(confChain); + saveConf(confChain->next); + saveRelations(confChain->next); menuConf(confChain, listenerChain); break; } @@ -766,11 +751,11 @@ void menuConf(ptConf confChain, ptListener listenerChain) case 4: { int day, month, year, time; - printf(" Jour : "); + printf("Jour : "); scanf("%d", &day); - printf(" Mois : "); + printf("Mois : "); scanf("%d", &month); - printf(" Annee : "); + printf("Annee : "); scanf("%d", &year); time = day + 31 * month + 365 * year; @@ -795,7 +780,7 @@ void menuConf(ptConf confChain, ptListener listenerChain) } } - saveConf(confChain); + saveConf(confChain->next); menuConf(confChain, listenerChain); } @@ -815,7 +800,9 @@ void menuAbo(ptConf confChain, ptListener listenerChain) system("cls"); drawMenu(options, 4); goToCoords(0, 12); - printf(" Que voulez-vous faire ? : "); + tasse(); + printf("\n"); + printf("Que voulez-vous faire ? : "); int choice; scanf("%d", &choice); @@ -823,14 +810,14 @@ void menuAbo(ptConf confChain, ptListener listenerChain) { case 1: { - ptListener py = listenerChain; + ptListener py = listenerChain->next; while (py->next != NULL) { - printf(" Id : %d\n Nom: %s\n Age: %d\n Niveau: %d\n", py->id, py->name, py->age, py->level); + printf("Id : %d\nNom: %s\nAge: %d\nNiveau: %d\n", py->id, py->name, py->age, py->level); if (py->confs->next != NULL) { - printConfList(py->confs); + printConfList(py->confs->next); } printf("\n"); py = py->next; @@ -846,20 +833,20 @@ void menuAbo(ptConf confChain, ptListener listenerChain) char name[20]; id = findListenerId(listenerChain); - printf(" Nom : "); + printf("Nom : "); scanf("%19s", &name); - printf(" Age : "); + printf("Age : "); scanf("%d", &age); - printf(" Niveau : "); + printf("Niveau : "); scanf("%d", &level); if (addListener(listenerChain, id, name, age, level) != -1) { - saveListeners(listenerChain); + saveListeners(listenerChain->next); } else { - printf(" Le niveau de l'abonne doit etre compris entre 0 et 5.\n\n"); + printf("Le niveau de l'abonne doit etre compris entre 0 et 5.\n\n"); system("pause"); } menuAbo(confChain, listenerChain); @@ -868,13 +855,24 @@ void menuAbo(ptConf confChain, ptListener listenerChain) case 3: { + ptListener px = listenerChain->next; + + printf("\n"); + while (px->next != NULL) + { + printf("%d : %s\n", px->id, px->name); + px = px->next; + } + printf("\n"); + int id; - printf(" Id de l'abonne a supprimer : "); + printf("Id de l'abonne a supprimer : "); scanf("%d", &id); removeListener(listenerChain, id); - saveListeners(listenerChain); + saveListeners(listenerChain->next); + saveRelations(confChain->next); menuAbo(confChain, listenerChain); break; } @@ -896,7 +894,7 @@ void menu(ptConf confChain, ptListener listenerChain) goToCoords(0, 13); tasse(); printf("\n"); - printf(" Que voulez-vous faire ? : "); + printf("Que voulez-vous faire ? : "); int choice; scanf("%d", &choice); @@ -912,21 +910,38 @@ void menu(ptConf confChain, ptListener listenerChain) case 3: { + ptConf px = confChain->next; + ptListener py = listenerChain->next; + + printf("\n"); + while (px->next != NULL) + { + printf("%d : %s\n", px->id, px->title); + px = px->next; + } + printf("\n"); + while (py->next != NULL) + { + printf("%d : %s\n", py->id, py->name); + py = py->next; + } + printf("\n"); + int confId, listenerId, grade; - printf(" Entrez l'ID de la conference : "); + printf("Entrez l'ID de la conference : "); scanf("%d", &confId); - printf(" Entrez l'ID du participant : "); + printf("Entrez l'ID du participant : "); scanf("%d", &listenerId); - printf(" Entrez la note attribuee par le participant : "); + printf("Entrez la note attribuee par le participant : "); scanf("%d", &grade); if (participateToConf(confChain, listenerChain, confId, listenerId, grade) != -1) { - saveRelations(confChain); + saveRelations(confChain->next); } else { - printf(" La note doit etre comprise entre 0 et 5 et l'abonne ne doit pas avoir deja participe a la conference\n\n"); + printf("La note doit etre comprise entre 0 et 5 et l'abonne ne doit pas avoir deja participe a la conference\n\n"); system("pause"); } @@ -952,7 +967,7 @@ void menu(ptConf confChain, ptListener listenerChain) px = px->next; } - printf(" La conférence la mieux notee est : %s\n\n", confMax->title); + printf("La conférence la mieux notee est : %s\n\n", confMax->title); system("pause"); menu(confChain, listenerChain);