diff --git a/a.exe b/a.exe deleted file mode 100644 index db9f8e0..0000000 Binary files a/a.exe and /dev/null differ diff --git a/conf.c b/conf.c index 9f8f9f6..7699dda 100644 --- a/conf.c +++ b/conf.c @@ -4,79 +4,83 @@ #include "conf.h" int findConfId(ptConf confChain) { - ptConf px = confChain; - int max = 0; + 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; + } - return max + 1; + return max + 1; } ptConf newConfChain() { - ptConf confChain = (ptConf) malloc(sizeof(tConf)); + ptConf confChain = (ptConf) malloc(sizeof(tConf)); - confChain -> next = NULL; + confChain -> next = NULL; - return confChain; + return confChain; } void addConf(ptConf confChain, char title[], char speaker[], int day, int month, int year) { - ptConf px = confChain; + ptConf px = confChain; - while (px -> next != NULL) { - px = px -> next; - } + while (px -> next != NULL) { + px = px -> next; + } - px -> id = findConfId(confChain); - px -> day = day; - px -> month = month; - px -> year = year; - strcpy(px -> title, title); - strcpy(px -> speaker, speaker); - // ajouter le builder de liste de participants - px -> next = (ptConf) malloc(sizeof(tConf)); - px -> next -> next = NULL; + px -> id = findConfId(confChain); + px -> day = day; + px -> month = month; + px -> year = year; + strcpy(px -> title, title); + strcpy(px -> speaker, speaker); + // ajouter le builder de liste de participants + px -> next = (ptConf) malloc(sizeof(tConf)); + px -> next -> next = NULL; } int findListenerId(ptListener listenerChain) { - ptListener px = listenerChain; - int max = 0; + 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; + } - return max + 1; + return max + 1; } ptListener newListenerChain() { - ptListener listenerChain = (ptListener) malloc(sizeof(tListener)); + ptListener listenerChain = (ptListener) malloc(sizeof(tListener)); - listenerChain -> prev = NULL; - listenerChain -> next = NULL; + listenerChain -> prev = NULL; + listenerChain -> next = NULL; - return listenerChain; + return listenerChain; } void addListener(ptListener listenerChain, char name[], int age, int level) { - ptListener px = listenerChain; + ptListener px = listenerChain; - while (px -> next != NULL) { - px = px -> next; - } + while (px -> next != NULL) { + px = px -> next; + } - px -> id = findListenerId(listenerChain); - strcpy(px -> name, name); - px -> age = age; - px -> level = level; - // ajouter la liste de conférences - px -> next = (ptListener) malloc(sizeof(tListener)); - px -> next -> next = NULL; - px -> next -> prev = px; -} + px -> id = findListenerId(listenerChain); + strcpy(px -> name, name); + px -> age = age; + px -> level = level; + // ajouter la liste de conférences + px -> next = (ptListener) malloc(sizeof(tListener)); + px -> next -> next = NULL; + px -> next -> prev = px; +} \ No newline at end of file diff --git a/data/confs b/data/confs index e69de29..9fb7602 100644 --- a/data/confs +++ b/data/confs @@ -0,0 +1,10 @@ +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,test,tesst,21,120,2023 +6,test,tesst,21,120,2023 +7,test,tesst,21,120,2023 +8,test,tesst,21,120,2023 +9,test,tesst,21,120,2023 +10,test,tesst,21,120,2023 diff --git a/data/listeners b/data/listeners index e69de29..a85b07f 100644 --- a/data/listeners +++ b/data/listeners @@ -0,0 +1,3 @@ +1,Roger,19,4 +2,Roger,19,4 +3,Roger,19,4 diff --git a/fileManager.c b/fileManager.c index e69de29..8c7b2eb 100644 --- a/fileManager.c +++ b/fileManager.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include "conf.h" + +void readConfs(ptConf confChain) { + FILE *file = fopen("./data/confs", "r"); + char line[100]; + char *tokens[6]; + char *token; + + if (file == NULL) { + printf("ça marche pas."); + return; + } + + while (fgets(line, sizeof(line), file)) { + token = strtok(line, ","); + + int i = 0; + + while (token != NULL && i < 6) { + tokens[i] = token; + i ++; + token = strtok(NULL, ","); + } + + addConf(confChain, tokens[1], tokens[2], atoi(tokens[3]), atoi(tokens[4]), atoi(tokens[5])); + } + + fclose(file); +} + +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; + } + fclose(file); +} + +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; + } + fclose(file); +} \ No newline at end of file diff --git a/fileManager.h b/fileManager.h index f1e082b..9be61c1 100644 --- a/fileManager.h +++ b/fileManager.h @@ -1,4 +1,10 @@ #ifndef FILE_MANAHGER_H #define FILE_MANAHGER_H +#include "conf.h" + +void readConfs(); +void saveConf(ptConf confChain); +void saveListeners(ptListener listenerChain); + #endif // FILE_MANAHGER_H \ No newline at end of file diff --git a/main.c b/main.c index cc8df3e..b06d6ad 100644 --- a/main.c +++ b/main.c @@ -2,33 +2,27 @@ #include #include "conf.h" #include "screenManager.h" +#include "fileManager.h" int main() { ptConf confChain = newConfChain(); ptListener listenerChain = newListenerChain(); + + readConfs(confChain); addConf(confChain, "test", "tesst", 21, 120, 2023); addConf(confChain, "test", "tesst", 21, 120, 2023); addConf(confChain, "test", "tesst", 21, 120, 2023); + addListener(listenerChain, "Roger", 19, 4); + addListener(listenerChain, "Roger", 19, 4); addListener(listenerChain, "Roger", 19, 4); - ptConf px = confChain; - ptListener py = listenerChain; - - while (px -> next != NULL) { - printf("title : %s\nspeaker : %s\n", px -> title, px -> speaker); - printf("%d/%d/%d\n", px -> day, px -> month, px -> year); - px = px -> next; - } - - while (py -> next != NULL) { - printf("name: %s\nage: %d\nlevel: %d", py -> name, py -> age, py -> level); - py = py -> next; - } - - //menu(); + //menu(confChain, listenerChain); + + saveConf(confChain); + saveListeners(listenerChain); return 0; -} +} \ No newline at end of file diff --git a/main.exe b/main.exe index c928904..829298b 100644 Binary files a/main.exe and b/main.exe differ diff --git a/screenManager.c b/screenManager.c index 200aab0..38965d2 100644 --- a/screenManager.c +++ b/screenManager.c @@ -2,6 +2,7 @@ #include #include #include "screenManager.h" +#include "conf.h" void goToCoords(int x, int y) { @@ -80,7 +81,7 @@ void drawMenu(char *options[], int lenght) { } -void menuConf() { +void menuConf(ptConf confChain, ptListener listenerChain) { char *options[] = {"1/ Voir la liste des conferences", "2/ Ajouter une conference", "3/ Suprimer une conference", "4/ Retour"}; system("cls"); drawMenu(options, 4); @@ -101,16 +102,16 @@ void menuConf() { break; case 4: - menu(); + menu(confChain, listenerChain); break; default: - menu(); + menu(confChain, listenerChain); break; } } -void menuAbo() { +void menuAbo(ptConf confChain, ptListener listenerChain) { char *options[] = {"1/ Voir la liste des abonnes", "2/ Ajouter un abonne", "3/ Suprimer un abonne", "4/ Retour"}; system("cls"); drawMenu(options, 4); @@ -131,16 +132,16 @@ void menuAbo() { break; case 4: - menu(); + menu(confChain, listenerChain); break; default: - menu(); + menu(confChain, listenerChain); break; } } -void menu() +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/ Quitter"}; system("cls"); @@ -153,11 +154,11 @@ void menu() switch (choice) { case 1: - menuConf(); + menuConf(confChain, listenerChain); break; case 2: - menuAbo(); + menuAbo(confChain, listenerChain); break; case 3: @@ -175,4 +176,4 @@ void menu() default: break; } -} +} \ No newline at end of file diff --git a/screenManager.h b/screenManager.h index 9036efc..1187df0 100644 --- a/screenManager.h +++ b/screenManager.h @@ -1,6 +1,8 @@ #ifndef SREEN_MANAGER_H #define SREEN_MANAGER_H -void menu(); +#include "conf.h" + +void menu(ptConf confChain, ptListener listenerChain); #endif // SCREEN_MANAGER