diff --git a/.gitignore b/.gitignore index d5417f3..ee66f5d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ +singleFile.c main.exe -.vscode/ -dataBackup/ \ No newline at end of file +.vscode/ \ No newline at end of file diff --git a/README.md b/README.md index 00a83f3..9af32b0 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Ce projet a pour but de créer un système de gestion de conférences en C. ## Requis -- gcc sur windows avec [MinGW](https://sourceforge.net/projects/mingw/) +- gcc sur windows (MinGW)[https://sourceforge.net/projects/mingw/] ## Installation diff --git a/conf.c b/conf.c index 96baeed..9278f44 100644 --- a/conf.c +++ b/conf.c @@ -3,331 +3,283 @@ #include #include "conf.h" -int findConfId(ptConf confChain) -{ +int findConfId(ptConf confChain) { ptConf px = confChain; int max = 0; - while (px->next != NULL) - { - if (px->id > max) - { - max = px->id; + while (px -> next != NULL) { + if (px -> id > max) { + max = px -> id; } - - px = px->next; + + px = px -> next; } return max + 1; } -ptConf newConfChain() -{ - ptConf confChain = (ptConf)malloc(sizeof(tConf)); +ptConf newConfChain() { + ptConf confChain = (ptConf) malloc(sizeof(tConf)); - confChain->next = (ptConf)malloc(sizeof(tConf)); - confChain->next->next = NULL; - confChain->id = -1; + confChain -> next = (ptConf) malloc(sizeof(tConf)); + confChain -> next -> next = NULL; + confChain -> id = -1; return confChain; } -void addConf(ptConf confChain, int id, char title[], char speaker[], int day, int month, int year) -{ +void addConf(ptConf confChain, int id, char title[], char speaker[], int day, int month, int year) { ptConf px = confChain; - while (px->next != NULL) - { - px = px->next; + while (px -> next != NULL) { + px = px -> next; } - px->id = id; - px->day = day; - px->month = month; - px->year = year; - strcpy(px->title, title); - strcpy(px->speaker, speaker); - px->listeners = (ptListenerList)malloc(sizeof(tListenerList)); - 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; + px -> id = id; + px -> day = day; + px -> month = month; + px -> year = year; + strcpy(px -> title, title); + strcpy(px -> speaker, speaker); + px -> listeners = (ptListenerList) malloc(sizeof(tListenerList)); + 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; } -void removeConf(ptConf confChain, int id) -{ +void removeConf(ptConf confChain, int id) { ptConf px = confChain; - while (px->next != NULL && px->next->id != id) - { - px = px->next; + while (px -> next != NULL && px -> next -> id != id) { + px = px -> next; } - if (px->next != NULL && px->next->id == id) - { - ptListenerList py = px->next->listeners->next; + 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; + while (py -> next != NULL) { + removeConfFromConfList(py -> listener -> confs, px -> next); + py = py -> next; } - ptConf tmp = px->next->next; - free(px->next); - px->next = tmp; + ptConf tmp = px -> next -> next; + free(px -> next); + px -> next = tmp; } } -int findListenerId(ptListener listenerChain) -{ +int findListenerId(ptListener listenerChain) { ptListener px = listenerChain; int max = 0; - while (px->next != NULL) - { - if (px->id > max) - { - max = px->id; + while (px -> next != NULL) { + if (px -> id > max) { + max = px -> id; } - - px = px->next; + + px = px -> next; } return max + 1; } -ptListener newListenerChain() -{ - ptListener listenerChain = (ptListener)malloc(sizeof(tListener)); +ptListener newListenerChain() { + ptListener listenerChain = (ptListener) malloc(sizeof(tListener)); - listenerChain->prev = NULL; - listenerChain->next = (ptListener)malloc(sizeof(tListener)); - listenerChain->next->prev = listenerChain; - listenerChain->next->next = NULL; - listenerChain->id = -1; + listenerChain -> prev = NULL; + listenerChain -> next = (ptListener) malloc(sizeof(tListener)); + listenerChain -> next -> prev = listenerChain; + listenerChain -> next -> next = NULL; + listenerChain -> id = -1; return listenerChain; } -int addListener(ptListener listenerChain, int id, char name[], int age, int level) -{ - if (level < 0 || level > 5) - { +int addListener(ptListener listenerChain, int id, char name[], int age, int level) { + if (level < 0 || level > 5) { return -1; } ptListener px = listenerChain; - while (px->next != NULL) - { - px = px->next; + while (px -> next != NULL) { + px = px -> next; } - px->id = id; - strcpy(px->name, name); - px->age = age; - px->level = level; - px->confs = (ptConfList)malloc(sizeof(tConfList)); - 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; + px -> id = id; + strcpy(px -> name, name); + px -> age = age; + px -> level = level; + px -> confs = (ptConfList) malloc(sizeof(tConfList)); + 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; return 0; } -void removeListener(ptListener listenerChain, int id) -{ +void removeListener(ptListener listenerChain, int id) { ptListener px = listenerChain; - while (px->next != NULL && px->next->id != id) - { - px = px->next; + while (px -> next != NULL && px -> next -> id != id) { + px = px -> next; } - if (px->next != NULL && px->next->id == id) - { - ptConfList py = px->next->confs->next; + 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; + while (py -> next != NULL) { + removeListenerFromListenerList(py -> conf -> listeners, px -> next); + py = py -> next; } - ptListener tmp = px->next->next; - free(px->next); - px->next = tmp; - px->next->prev = px; + ptListener tmp = px -> next -> next; + free(px -> next); + px -> next = tmp; + px -> next -> prev = px; } } -void addConfToConfList(ptConfList confList, ptConf conf, int grade) -{ +void addConfToConfList(ptConfList confList, ptConf conf, int grade) { + ptConfList px = confList; + + while (px -> next != NULL) { + px = px -> next; + } + + px -> conf = conf; + px -> next = (ptConfList) malloc(sizeof(tConfList)); + px -> grade = grade; + px -> next -> next = NULL; +} + +void removeConfFromConfList(ptConfList confList, ptConf conf) { ptConfList px = confList; - while (px->next != NULL) - { - px = px->next; + while (px -> next != NULL && px -> next -> conf != conf) { + px = px -> next; } - px->conf = conf; - px->next = (ptConfList)malloc(sizeof(tConfList)); - px->grade = grade; - px->next->next = NULL; -} - -void removeConfFromConfList(ptConfList confList, ptConf conf) -{ - ptConfList px = confList; - - while (px->next != NULL && px->next->conf != conf) - { - px = px->next; - } - - if (px->next != NULL && 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; } } -void printConfList(ptConfList confList) -{ - ptConfList px = confList; - - printf("Participation aux conferences : "); - while (px->next != NULL) - { - printf("%s(%d) ", px->conf->title, px->grade); - px = px->next; - } - printf("\n"); +void printConfList(ptConfList confList) { + ptConfList px = confList; + + printf("Participation aux conferences : "); + while (px -> next != NULL) { + printf("%s(%d) ", px -> conf -> title, px -> grade); + px = px -> next; + } + printf("\n"); } -void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade) -{ +void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade) { + ptListenerList px = listenerList; + + while (px -> next != NULL) { + px = px -> next; + } + + px -> listener = listener; + px -> next = (ptListenerList) malloc(sizeof(tListenerList)); + px -> grade = grade; + px -> next -> next = NULL; +} + +void removeListenerFromListenerList(ptListenerList listenerList, ptListener listener) { ptListenerList px = listenerList; - while (px->next != NULL) - { - px = px->next; + while (px -> next != NULL && px -> next -> listener != listener) { + px = px -> next; } - px->listener = listener; - px->next = (ptListenerList)malloc(sizeof(tListenerList)); - px->grade = grade; - 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; + 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 : "); - while (px->next != NULL) - { - printf("%s(%d) ", px->listener->name, px->grade); - px = px->next; - } - printf("\n"); +void printListenerList(ptListenerList listenerList) { + ptListenerList px = listenerList; + + printf("Participants : "); + while (px -> next != NULL) { + printf("%s(%d) ", px -> listener -> name, px -> grade); + px = px -> next; + } + printf("\n"); } -int participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade) -{ - if (grade < 0 || grade > 5) - { +int participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade) { + if (grade < 0 || grade > 5) { return -1; } - ptConf px = confChain; - ptListener py = listenerChain; - ptListenerList pz; - - while (px->next != NULL && px->id != confId) - { - px = px->next; - } - - pz = px->listeners->next; - while (pz->next != NULL) - { - if (pz->listener->id == listenerId) - { - return -2; - } - pz = pz->next; - } - - while (py->next != NULL && py->id != listenerId) - { - py = py->next; - } - - if (px->id != confId || py->id != listenerId) - { - return -2; - } - - addListenerToListenerList(px->listeners, py, grade); - addConfToConfList(py->confs, px, grade); + ptConf px = confChain; + ptListener py = listenerChain; + ptListenerList pz; + + while (px -> next != NULL && px -> id != confId) { + px = px -> next; + } + + pz = px -> listeners -> next; + while (pz -> next != NULL) { + if (pz -> listener -> id == listenerId) { + return -2; + } + pz = pz -> next; + } + + while (py -> next != NULL && py -> id != listenerId) { + py = py -> next; + } + + if (px -> id != confId || py -> id != listenerId) { + return -2; + } + + addListenerToListenerList(px -> listeners, py, grade); + addConfToConfList(py -> confs, px, grade); return 0; } -int confGradeAvg(ptConf conf) -{ - ptListenerList px = conf->listeners->next; +int confGradeAvg(ptConf conf) { + ptListenerList px = conf -> listeners -> next; int total = 0, nb = 0; - while (px->next != NULL) - { - total += px->grade; + while (px -> next != NULL) { + total += px -> grade; nb++; - px = px->next; + px = px -> next; } - if (nb != 0) - { + if (nb != 0) { return total / nb; - } - else - { + } else { return -1; } + } -int confParticipations(ptConf conf) -{ - ptListenerList px = conf->listeners->next; +int confParticipations(ptConf conf) { + ptListenerList px = conf -> listeners -> next; int nb = 0; - while (px->next != NULL) - { + while (px -> next != NULL) { nb++; - px = px->next; + px = px -> next; } return nb; diff --git a/conf.h b/conf.h index 98a2765..6898a2b 100644 --- a/conf.h +++ b/conf.h @@ -3,47 +3,43 @@ struct listenerList; -typedef struct conf -{ +typedef struct conf { int id; char title[30]; char speaker[20]; int day; int month; int year; - struct listenerList *listeners; - struct conf *next; + struct listenerList* listeners; + struct conf* next; } tConf; -typedef struct confList -{ - struct conf *conf; +typedef struct confList { + struct conf* conf; int grade; - struct confList *next; + struct confList* next; } tConfList; -typedef struct listener -{ +typedef struct listener { int id; char name[20]; int age; int level; - struct confList *confs; - struct listener *prev; - struct listener *next; + struct confList* confs; + struct listener* prev; + struct listener* next; } tListener; -typedef struct listenerList -{ - struct listener *listener; +typedef struct listenerList { + struct listener* listener; int grade; - struct listenerList *next; + struct listenerList* next; } tListenerList; -typedef tConf *ptConf; -typedef tListener *ptListener; -typedef tConfList *ptConfList; -typedef tListenerList *ptListenerList; +typedef tConf* ptConf; +typedef tListener* ptListener; +typedef tConfList* ptConfList; +typedef tListenerList* ptListenerList; int findConfId(ptConf confChain); ptConf newConfChain(); diff --git a/data/confs b/data/confs index e69de29..fa10f60 100644 --- a/data/confs +++ b/data/confs @@ -0,0 +1,12 @@ +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 +5,Crysper_case9_et_ADN,Peggy_Baron,18,10,2023 +6,Materiaux_de_demain,Emmanuel_Chirache,15,11,2023 +7,Les_IA,Matthieu_Maurer,1,6,2023 +8,Therories_du_complots,Jean_Benoit,1,4,2021 +9,Le_lacet_irlandais,Mick_Oconnell,31,3,2022 +10,Litterature_et_SF,Terry_Pratchett,15,5,2021 +11,Les_chaises_en_bois,David,24,12,2023 +12,cybersecurite_des_coquillages,Bob,6,2,2024 diff --git a/data/listeners b/data/listeners index e69de29..d2f1a19 100644 --- a/data/listeners +++ b/data/listeners @@ -0,0 +1,19 @@ +1,Simon,21,3 +3,Thomas,20,3 +4,Victor,19,2 +5,Lukian,19,2 +6,Natacha,18,1 +7,Caroline,22,4 +8,Lucas,23,4 +9,Clodine,64,3 +10,Kevin,26,3 +11,Titouan,18,1 +12,Louise,20,3 +13,Chayma,22,5 +14,Elisa,23,5 +15,Erwan,19,2 +18,Marion,17,1 +19,Tom,17,1 +20,Sebastien,45,5 +21,Jean,50,5 +22,Patrick,15,5 diff --git a/data/relations b/data/relations index e69de29..17d29d8 100644 --- a/data/relations +++ b/data/relations @@ -0,0 +1,6 @@ +1:12;0,1;4 +2:12;0,1;4 +3:12;0,1;4 +4:12;0,1;4 +9:20;5 +10:21;5 diff --git a/dataBackup/confs b/dataBackup/confs new file mode 100644 index 0000000..fa10f60 --- /dev/null +++ b/dataBackup/confs @@ -0,0 +1,12 @@ +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 +5,Crysper_case9_et_ADN,Peggy_Baron,18,10,2023 +6,Materiaux_de_demain,Emmanuel_Chirache,15,11,2023 +7,Les_IA,Matthieu_Maurer,1,6,2023 +8,Therories_du_complots,Jean_Benoit,1,4,2021 +9,Le_lacet_irlandais,Mick_Oconnell,31,3,2022 +10,Litterature_et_SF,Terry_Pratchett,15,5,2021 +11,Les_chaises_en_bois,David,24,12,2023 +12,cybersecurite_des_coquillages,Bob,6,2,2024 diff --git a/dataBackup/listeners b/dataBackup/listeners new file mode 100644 index 0000000..d2f1a19 --- /dev/null +++ b/dataBackup/listeners @@ -0,0 +1,19 @@ +1,Simon,21,3 +3,Thomas,20,3 +4,Victor,19,2 +5,Lukian,19,2 +6,Natacha,18,1 +7,Caroline,22,4 +8,Lucas,23,4 +9,Clodine,64,3 +10,Kevin,26,3 +11,Titouan,18,1 +12,Louise,20,3 +13,Chayma,22,5 +14,Elisa,23,5 +15,Erwan,19,2 +18,Marion,17,1 +19,Tom,17,1 +20,Sebastien,45,5 +21,Jean,50,5 +22,Patrick,15,5 diff --git a/dataBackup/relations b/dataBackup/relations new file mode 100644 index 0000000..17d29d8 --- /dev/null +++ b/dataBackup/relations @@ -0,0 +1,6 @@ +1:12;0,1;4 +2:12;0,1;4 +3:12;0,1;4 +4:12;0,1;4 +9:20;5 +10:21;5 diff --git a/fileManager.c b/fileManager.c index c4a1449..6c81bec 100644 --- a/fileManager.c +++ b/fileManager.c @@ -3,20 +3,17 @@ #include #include "conf.h" -void readConfs(ptConf confChain) -{ +void readConfs(ptConf confChain) { FILE *file = fopen("./data/confs", "r"); char line[100]; char *token; - if (file == NULL) - { + if (file == NULL) { printf("ça marche pas."); return; } - while (fgets(line, sizeof(line), file)) - { + while (fgets(line, sizeof(line), file)) { int id = atoi(strtok(line, ",")); char *title = strtok(NULL, ","); char *speaker = strtok(NULL, ","); @@ -30,20 +27,17 @@ void readConfs(ptConf confChain) fclose(file); } -void readListeners(ptListener listenerChain) -{ +void readListeners(ptListener listenerChain) { FILE *file = fopen("./data/listeners", "r"); char line[100]; char *token; - if (file == NULL) - { + if (file == NULL) { printf("ça marche pas."); return; } - while (fgets(line, sizeof(line), file)) - { + while (fgets(line, sizeof(line), file)) { int id = atoi(strtok(line, ",")); char *name = strtok(NULL, ","); int day = atoi(strtok(NULL, ",")); @@ -54,25 +48,21 @@ void readListeners(ptListener listenerChain) fclose(file); } -void readRelations(ptConf confChain, ptListener listenerChain) -{ - FILE *file = fopen("./data/relations", "r"); - char line[100]; - char *token1; +void readRelations(ptConf confChain, ptListener listenerChain) { + FILE *file = fopen("./data/relations", "r"); + char line[100]; + char *token1; char *token2; - - if (file == NULL) - { - printf("ça marche pas."); - return; - } - - while (fgets(line, sizeof(line), file)) - { + + if (file == NULL) { + printf("ça marche pas."); + return; + } + + while (fgets(line, sizeof(line), file)) { int confId = atoi(strtok(line, ":")); - while ((token1 = strtok(NULL, ";")) != NULL && (token2 = strtok(NULL, ",")) != NULL) - { + while ((token1 = strtok(NULL, ";")) != NULL && (token2 = strtok(NULL, ",")) != NULL) { participateToConf(confChain, listenerChain, confId, atoi(token1), atoi(token2)); } } @@ -80,61 +70,50 @@ void readRelations(ptConf confChain, ptListener listenerChain) fclose(file); } -void saveConf(ptConf confChain) -{ +void saveConf(ptConf confChain) { FILE *file = fopen("./data/confs", "w"); ptConf px = confChain; - while (px->next != NULL) - { - fprintf(file, "%d,%s,%s,%d,%d,%d\n", px->id, px->title, px->speaker, px->day, px->month, px->year); - px = px->next; + while(px -> next != NULL){ + fprintf(file,"%d,%s,%s,%d,%d,%d\n",px -> id,px -> title,px -> speaker,px -> day,px -> month,px -> year); + px = px -> next; } fclose(file); } -void saveListeners(ptListener listenerChain) -{ +void saveListeners(ptListener listenerChain) { FILE *file = fopen("./data/listeners", "w"); ptListener px = listenerChain; - while (px->next != NULL) - { - fprintf(file, "%d,%s,%d,%d\n", px->id, px->name, px->age, px->level); - px = px->next; + while(px -> next != NULL){ + fprintf(file,"%d,%s,%d,%d\n",px -> id,px -> name,px -> age,px -> level); + px = px -> next; } fclose(file); } -void saveRelations(ptConf confChain) -{ +void saveRelations(ptConf confChain) { FILE *file = fopen("./data/relations", "w"); ptConf px = confChain; ptListenerList py; printf("test"); - while (px->next != NULL) - { + while(px -> next != NULL){ printf("test"); - py = px->listeners->next; + py = px -> listeners -> next; - if (py->next != NULL) - { - fprintf(file, "%d:", px->id); - } + if (py -> next != NULL) { + fprintf(file, "%d:", px -> id); + } - while (py->next != NULL) - { - fprintf(file, "%d;%d", py->listener->id, py->grade); - if (py->next->next != NULL) - { + while (py -> next != NULL) { + fprintf(file, "%d;%d", py -> listener -> id, py -> grade); + if (py -> next -> next != NULL) { fprintf(file, ","); - } - else - { + } else { fprintf(file, "\n"); } - py = py->next; + py = py -> next; } - px = px->next; + px = px -> next; } fclose(file); } \ No newline at end of file