This commit is contained in:
Lukian LEIZOUR 2023-11-20 14:42:20 +01:00
parent aa5045a797
commit dec244496a
10 changed files with 148 additions and 76 deletions

BIN
a.exe

Binary file not shown.

102
conf.c
View file

@ -4,79 +4,83 @@
#include "conf.h" #include "conf.h"
int findConfId(ptConf confChain) { int findConfId(ptConf confChain) {
ptConf px = confChain; ptConf px = confChain;
int max = 0; int max = 0;
while (px -> next != NULL) { while (px -> next != NULL) {
if (px -> id > max) { if (px -> id > max) {
max = px -> id; max = px -> id;
} }
}
px = px -> next;
}
return max + 1; return max + 1;
} }
ptConf newConfChain() { 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) { void addConf(ptConf confChain, char title[], char speaker[], int day, int month, int year) {
ptConf px = confChain; ptConf px = confChain;
while (px -> next != NULL) { while (px -> next != NULL) {
px = px -> next; px = px -> next;
} }
px -> id = findConfId(confChain); px -> id = findConfId(confChain);
px -> day = day; px -> day = day;
px -> month = month; px -> month = month;
px -> year = year; px -> year = year;
strcpy(px -> title, title); strcpy(px -> title, title);
strcpy(px -> speaker, speaker); strcpy(px -> speaker, speaker);
// ajouter le builder de liste de participants // ajouter le builder de liste de participants
px -> next = (ptConf) malloc(sizeof(tConf)); px -> next = (ptConf) malloc(sizeof(tConf));
px -> next -> next = NULL; px -> next -> next = NULL;
} }
int findListenerId(ptListener listenerChain) { int findListenerId(ptListener listenerChain) {
ptListener px = listenerChain; ptListener px = listenerChain;
int max = 0; int max = 0;
while (px -> next != NULL) { while (px -> next != NULL) {
if (px -> id > max) { if (px -> id > max) {
max = px -> id; max = px -> id;
} }
}
px = px -> next;
}
return max + 1; return max + 1;
} }
ptListener newListenerChain() { ptListener newListenerChain() {
ptListener listenerChain = (ptListener) malloc(sizeof(tListener)); ptListener listenerChain = (ptListener) malloc(sizeof(tListener));
listenerChain -> prev = NULL; listenerChain -> prev = NULL;
listenerChain -> next = NULL; listenerChain -> next = NULL;
return listenerChain; return listenerChain;
} }
void addListener(ptListener listenerChain, char name[], int age, int level) { void addListener(ptListener listenerChain, char name[], int age, int level) {
ptListener px = listenerChain; ptListener px = listenerChain;
while (px -> next != NULL) { while (px -> next != NULL) {
px = px -> next; px = px -> next;
} }
px -> id = findListenerId(listenerChain); px -> id = findListenerId(listenerChain);
strcpy(px -> name, name); strcpy(px -> name, name);
px -> age = age; px -> age = age;
px -> level = level; px -> level = level;
// ajouter la liste de conférences // ajouter la liste de conférences
px -> next = (ptListener) malloc(sizeof(tListener)); px -> next = (ptListener) malloc(sizeof(tListener));
px -> next -> next = NULL; px -> next -> next = NULL;
px -> next -> prev = px; px -> next -> prev = px;
} }

View file

@ -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

View file

@ -0,0 +1,3 @@
1,Roger,19,4
2,Roger,19,4
3,Roger,19,4

View file

@ -0,0 +1,52 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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);
}

View file

@ -1,4 +1,10 @@
#ifndef FILE_MANAHGER_H #ifndef FILE_MANAHGER_H
#define FILE_MANAHGER_H #define FILE_MANAHGER_H
#include "conf.h"
void readConfs();
void saveConf(ptConf confChain);
void saveListeners(ptListener listenerChain);
#endif // FILE_MANAHGER_H #endif // FILE_MANAHGER_H

26
main.c
View file

@ -2,33 +2,27 @@
#include <stdio.h> #include <stdio.h>
#include "conf.h" #include "conf.h"
#include "screenManager.h" #include "screenManager.h"
#include "fileManager.h"
int main() int main()
{ {
ptConf confChain = newConfChain(); ptConf confChain = newConfChain();
ptListener listenerChain = newListenerChain(); 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); 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); addListener(listenerChain, "Roger", 19, 4);
ptConf px = confChain; //menu(confChain, listenerChain);
ptListener py = listenerChain;
saveConf(confChain);
while (px -> next != NULL) { saveListeners(listenerChain);
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();
return 0; return 0;
} }

BIN
main.exe

Binary file not shown.

View file

@ -2,6 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <windows.h> #include <windows.h>
#include "screenManager.h" #include "screenManager.h"
#include "conf.h"
void goToCoords(int x, int y) 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"}; char *options[] = {"1/ Voir la liste des conferences", "2/ Ajouter une conference", "3/ Suprimer une conference", "4/ Retour"};
system("cls"); system("cls");
drawMenu(options, 4); drawMenu(options, 4);
@ -101,16 +102,16 @@ void menuConf() {
break; break;
case 4: case 4:
menu(); menu(confChain, listenerChain);
break; break;
default: default:
menu(); menu(confChain, listenerChain);
break; 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"}; char *options[] = {"1/ Voir la liste des abonnes", "2/ Ajouter un abonne", "3/ Suprimer un abonne", "4/ Retour"};
system("cls"); system("cls");
drawMenu(options, 4); drawMenu(options, 4);
@ -131,16 +132,16 @@ void menuAbo() {
break; break;
case 4: case 4:
menu(); menu(confChain, listenerChain);
break; break;
default: default:
menu(); menu(confChain, listenerChain);
break; 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"}; 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"); system("cls");
@ -153,11 +154,11 @@ void menu()
switch (choice) switch (choice)
{ {
case 1: case 1:
menuConf(); menuConf(confChain, listenerChain);
break; break;
case 2: case 2:
menuAbo(); menuAbo(confChain, listenerChain);
break; break;
case 3: case 3:
@ -175,4 +176,4 @@ void menu()
default: default:
break; break;
} }
} }

View file

@ -1,6 +1,8 @@
#ifndef SREEN_MANAGER_H #ifndef SREEN_MANAGER_H
#define SREEN_MANAGER_H #define SREEN_MANAGER_H
void menu(); #include "conf.h"
void menu(ptConf confChain, ptListener listenerChain);
#endif // SCREEN_MANAGER #endif // SCREEN_MANAGER