This commit is contained in:
Lukian LEIZOUR 2023-11-30 15:59:10 +01:00
parent a70b104817
commit 36319a7b7f
8 changed files with 207 additions and 153 deletions

2
.gitignore vendored
View file

@ -1,2 +0,0 @@
main.exe
singleFile.exe

10
conf.c
View file

@ -91,6 +91,7 @@ ptListener newListenerChain() {
listenerChain -> prev = NULL; listenerChain -> prev = NULL;
listenerChain -> next = (ptListener) malloc(sizeof(tListener)); listenerChain -> next = (ptListener) malloc(sizeof(tListener));
listenerChain -> next -> prev = listenerChain; listenerChain -> next -> prev = listenerChain;
listenerChain -> next -> next = NULL;
listenerChain -> id = -1; listenerChain -> id = -1;
return listenerChain; return listenerChain;
@ -159,20 +160,15 @@ void addConfToConfList(ptConfList confList, ptConf conf, int grade) {
void removeConfFromConfList(ptConfList confList, ptConf conf) { void removeConfFromConfList(ptConfList confList, ptConf conf) {
ptConfList px = confList; ptConfList px = confList;
while (px -> next != NULL && px -> conf != conf) { while (px -> next != NULL && px -> next -> conf != conf) {
px = px -> next; px = px -> next;
} }
printConfList(confList -> next);
printf("%d\n", px -> conf -> id);
if (px -> next != NULL && px -> next -> conf == conf) { if (px -> next != NULL && px -> next -> conf == conf) {
ptConfList tmp = px -> next -> next; ptConfList tmp = px -> next -> next;
free(px -> next); free(px -> next);
px -> next = tmp; px -> next = tmp;
} }
system("pause");
} }
void printConfList(ptConfList confList) { void printConfList(ptConfList confList) {
@ -202,7 +198,7 @@ void addListenerToListenerList(ptListenerList listenerList, ptListener listener,
void removeListenerFromListenerList(ptListenerList listenerList, ptListener listener) { void removeListenerFromListenerList(ptListenerList listenerList, ptListener listener) {
ptListenerList px = listenerList; ptListenerList px = listenerList;
while (px -> next != NULL && px -> listener != listener) { while (px -> next != NULL && px -> next -> listener != listener) {
px = px -> next; px = px -> next;
} }

View file

@ -1,3 +1,4 @@
1,Rapport_du_GIEC,Jean_Jouzzel,15,11,2022
2,L_esprit_critique,Thomas_Durand,6,2,2023 2,L_esprit_critique,Thomas_Durand,6,2,2023
3,La_resilience,Arthur_Keller,20,10,2022 3,La_resilience,Arthur_Keller,20,10,2022
4,American_lobbying,Salah_Oueslati,30,11,2023 4,American_lobbying,Salah_Oueslati,30,11,2023

View file

@ -1,2 +1,5 @@
1:12;0,1;4 1:12;0,1;4
2:12;0,1;4
3:12;0,1;4
4:12;0,1;4
9:20;5 9:20;5

View file

@ -94,8 +94,10 @@ void saveRelations(ptConf confChain) {
FILE *file = fopen("./data/relations", "w"); FILE *file = fopen("./data/relations", "w");
ptConf px = confChain; ptConf px = confChain;
ptListenerList py; ptListenerList py;
printf("test");
while(px -> next != NULL){ while(px -> next != NULL){
py = px -> listeners; printf("test");
py = px -> listeners -> next;
if (py -> next != NULL) { if (py -> next != NULL) {
fprintf(file, "%d:", px -> id); fprintf(file, "%d:", px -> id);

BIN
main.exe Normal file

Binary file not shown.

View file

@ -105,6 +105,8 @@ void menuConf(ptConf confChain, ptListener listenerChain) {
system("cls"); system("cls");
drawMenu(options, 5); drawMenu(options, 5);
goToCoords(0, 13); goToCoords(0, 13);
tasse();
printf("\n");
printf("Que voulez-vous faire ? : "); printf("Que voulez-vous faire ? : ");
int choice; int choice;
scanf("%d", &choice); scanf("%d", &choice);
@ -160,6 +162,15 @@ void menuConf(ptConf confChain, ptListener listenerChain) {
case 3: 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; int id;
printf("Id de la conference a supprimer : "); printf("Id de la conference a supprimer : ");
@ -167,6 +178,7 @@ void menuConf(ptConf confChain, ptListener listenerChain) {
removeConf(confChain, id); removeConf(confChain, id);
saveConf(confChain -> next); saveConf(confChain -> next);
saveRelations(confChain -> next);
menuConf(confChain, listenerChain); menuConf(confChain, listenerChain);
break; break;
} }
@ -216,6 +228,8 @@ void menuAbo(ptConf confChain, ptListener listenerChain) {
system("cls"); system("cls");
drawMenu(options, 4); drawMenu(options, 4);
goToCoords(0, 12); goToCoords(0, 12);
tasse();
printf("\n");
printf("Que voulez-vous faire ? : "); printf("Que voulez-vous faire ? : ");
int choice; int choice;
scanf("%d", &choice); scanf("%d", &choice);
@ -264,6 +278,15 @@ void menuAbo(ptConf confChain, ptListener listenerChain) {
case 3: 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; int id;
printf("Id de l'abonne a supprimer : "); printf("Id de l'abonne a supprimer : ");
@ -271,6 +294,7 @@ void menuAbo(ptConf confChain, ptListener listenerChain) {
removeListener(listenerChain, id); removeListener(listenerChain, id);
saveListeners(listenerChain -> next); saveListeners(listenerChain -> next);
saveRelations(confChain -> next);
menuAbo(confChain, listenerChain); menuAbo(confChain, listenerChain);
break; break;
} }
@ -308,6 +332,21 @@ void menu(ptConf confChain, ptListener listenerChain)
case 3: 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; int confId, listenerId, grade;
printf("Entrez l'ID de la conference : "); printf("Entrez l'ID de la conference : ");
scanf("%d", &confId); scanf("%d", &confId);
@ -317,7 +356,7 @@ void menu(ptConf confChain, ptListener listenerChain)
scanf("%d", &grade); scanf("%d", &grade);
if (participateToConf(confChain, listenerChain, confId, listenerId, grade) != -1) { if (participateToConf(confChain, listenerChain, confId, listenerId, grade) != -1) {
saveRelations(confChain); saveRelations(confChain -> next);
} else { } 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"); system("pause");

View file

@ -60,8 +60,10 @@ ptListener newListenerChain();
int addListener(ptListener listenerChain, int id, char name[], int age, int level); int addListener(ptListener listenerChain, int id, char name[], int age, int level);
void removeListener(ptListener listenerChain, int id); void removeListener(ptListener listenerChain, int id);
void addConfToConfList(ptConfList confList, ptConf conf, int grade); void addConfToConfList(ptConfList confList, ptConf conf, int grade);
void removeConfFromConfList(ptConfList confList, ptConf conf);
void printConfList(ptConfList confList); void printConfList(ptConfList confList);
void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade); void addListenerToListenerList(ptListenerList listenerList, ptListener listener, int grade);
void removeListenerFromListenerList(ptListenerList listenerList, ptListener listener);
void printListenerList(ptListenerList listenerList); void printListenerList(ptListenerList listenerList);
int participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade); int participateToConf(ptConf confChain, ptListener listenerChain, int confId, int listenerId, int grade);
int confGradeAvg(ptConf conf); int confGradeAvg(ptConf conf);
@ -89,7 +91,9 @@ ptConf newConfChain()
{ {
ptConf confChain = (ptConf)malloc(sizeof(tConf)); ptConf confChain = (ptConf)malloc(sizeof(tConf));
confChain->next = NULL; confChain->next = (ptConf)malloc(sizeof(tConf));
confChain->next->next = NULL;
confChain->id = -1;
return confChain; 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->title, title);
strcpy(px->speaker, speaker); strcpy(px->speaker, speaker);
px->listeners = (ptListenerList)malloc(sizeof(tListenerList)); 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 = (ptConf)malloc(sizeof(tConf));
px->next->next = NULL; px->next->next = NULL;
} }
@ -119,42 +125,24 @@ void removeConf(ptConf confChain, int id)
{ {
ptConf px = confChain; ptConf px = confChain;
if (px->next == NULL)
{
return;
}
else if (px->next->next == NULL)
{
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) while (px->next != NULL && px->next->id != id)
{ {
px = px->next; px = px->next;
} }
if (px->next->id == id) if (px->next != NULL && px->next->id == id)
{ {
ptConf tmp = px->next; ptListenerList py = px->next->listeners->next;
px->next = px->next->next;
free(tmp); while (py->next != NULL)
{
removeConfFromConfList(py->listener->confs, px->next);
py = py->next;
} }
ptConf tmp = px->next->next;
free(px->next);
px->next = tmp;
} }
} }
@ -181,7 +169,10 @@ 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 = (ptListener)malloc(sizeof(tListener));
listenerChain->next->prev = listenerChain;
listenerChain->next->next = NULL;
listenerChain->id = -1;
return listenerChain; return listenerChain;
} }
@ -205,7 +196,9 @@ int addListener(ptListener listenerChain, int id, char name[], int age, int leve
px->age = age; px->age = age;
px->level = level; px->level = level;
px->confs = (ptConfList)malloc(sizeof(tConfList)); 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 = (ptListener)malloc(sizeof(tListener));
px->next->next = NULL; px->next->next = NULL;
px->next->prev = px; 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) void removeListener(ptListener listenerChain, int id)
{ {
ptListener px = listenerChain; ptListener px = listenerChain;
if (px->next == NULL)
{
return;
}
else if (px->id == id && 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) while (px->next != NULL && px->next->id != id)
{ {
px = px->next; px = px->next;
} }
if (px->next->id == id) if (px->next != NULL && px->next->id == id)
{ {
ptListener tmp = px->next; ptConfList py = px->next->confs->next;
px->next = px->next->next;
px->next->prev = px; while (py->next != NULL)
free(tmp); {
removeListenerFromListenerList(py->conf->listeners, px->next);
py = py->next;
} }
ptListener tmp = px->next->next;
free(px->next);
px->next = tmp;
px->next->prev = px;
} }
} }
@ -268,46 +246,22 @@ void addConfToConfList(ptConfList confList, ptConf conf, int grade)
px->next->next = NULL; px->next->next = NULL;
} }
void removeConfFromConfList(ptConf confChain, ptConfList confList, ptConf conf) void removeConfFromConfList(ptConfList confList, ptConf conf)
{
if (confList->next == NULL)
{
return;
}
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; ptConfList px = confList;
while (px->next != NULL && px->next->conf != conf) while (px->next != NULL && px->next->conf != conf)
{ {
if (confChain == conf && px->conf == conf->next) {
px->conf
}
px = px->next; px = px->next;
} }
if (px->next->conf == conf) { if (px->next != NULL && px->next->conf == conf)
{
ptConfList tmp = px->next->next; ptConfList tmp = px->next->next;
free(px->next); free(px->next);
px->next = tmp; px->next = tmp;
} }
} }
}
void printConfList(ptConfList confList) void printConfList(ptConfList confList)
{ {
@ -337,6 +291,23 @@ void addListenerToListenerList(ptListenerList listenerList, ptListener listener,
px->next->next = NULL; 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) void printListenerList(ptListenerList listenerList)
{ {
ptListenerList px = listenerList; ptListenerList px = listenerList;
@ -366,7 +337,7 @@ int participateToConf(ptConf confChain, ptListener listenerChain, int confId, in
px = px->next; px = px->next;
} }
pz = px->listeners; pz = px->listeners->next;
while (pz->next != NULL) while (pz->next != NULL)
{ {
if (pz->listener->id == listenerId) if (pz->listener->id == listenerId)
@ -394,7 +365,7 @@ int participateToConf(ptConf confChain, ptListener listenerChain, int confId, in
int confGradeAvg(ptConf conf) int confGradeAvg(ptConf conf)
{ {
ptListenerList px = conf->listeners; ptListenerList px = conf->listeners->next;
int total = 0, nb = 0; int total = 0, nb = 0;
while (px->next != NULL) while (px->next != NULL)
@ -416,7 +387,7 @@ int confGradeAvg(ptConf conf)
int confParticipations(ptConf conf) int confParticipations(ptConf conf)
{ {
ptListenerList px = conf->listeners; ptListenerList px = conf->listeners->next;
int nb = 0; int nb = 0;
while (px->next != NULL) while (px->next != NULL)
@ -545,9 +516,11 @@ void saveRelations(ptConf confChain)
FILE *file = fopen("./data/relations", "w"); FILE *file = fopen("./data/relations", "w");
ptConf px = confChain; ptConf px = confChain;
ptListenerList py; ptListenerList py;
printf("test");
while (px->next != NULL) while (px->next != NULL)
{ {
py = px->listeners; printf("test");
py = px->listeners->next;
if (py->next != NULL) if (py->next != NULL)
{ {
@ -585,7 +558,6 @@ void drawMenu(char *options[], int lenght);
void tasse(); void tasse();
void menuConf(ptConf confChain, ptListener listenerChain); void menuConf(ptConf confChain, ptListener listenerChain);
void menuAbo(ptConf confChain, ptListener listenerChain); void menuAbo(ptConf confChain, ptListener listenerChain);
void menu(ptConf confChain, ptListener listenerChain); void menu(ptConf confChain, ptListener listenerChain);
void goToCoords(int x, int y) void goToCoords(int x, int y)
@ -694,6 +666,8 @@ void menuConf(ptConf confChain, ptListener listenerChain)
system("cls"); system("cls");
drawMenu(options, 5); drawMenu(options, 5);
goToCoords(0, 13); goToCoords(0, 13);
tasse();
printf("\n");
printf("Que voulez-vous faire ? : "); printf("Que voulez-vous faire ? : ");
int choice; int choice;
scanf("%d", &choice); scanf("%d", &choice);
@ -702,7 +676,7 @@ void menuConf(ptConf confChain, ptListener listenerChain)
{ {
case 1: case 1:
{ {
ptConf px = confChain; ptConf px = confChain->next;
while (px->next != NULL) while (px->next != NULL)
{ {
@ -711,7 +685,7 @@ void menuConf(ptConf confChain, ptListener listenerChain)
printf("Nombre de participants : %d\n", confParticipations(px)); printf("Nombre de participants : %d\n", confParticipations(px));
if (px->listeners->next != NULL) if (px->listeners->next != NULL)
{ {
printListenerList(px->listeners); printListenerList(px->listeners->next);
} }
int avg; int avg;
if ((avg = confGradeAvg(px) != -1)) if ((avg = confGradeAvg(px) != -1))
@ -745,20 +719,31 @@ void menuConf(ptConf confChain, ptListener listenerChain)
scanf("%d", &year); scanf("%d", &year);
addConf(confChain, id, title, speaker, day, month, year); addConf(confChain, id, title, speaker, day, month, year);
saveConf(confChain); saveConf(confChain->next);
menuConf(confChain, listenerChain); menuConf(confChain, listenerChain);
break; break;
} }
case 3: 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; int id;
printf("Id de la conference a supprimer : "); printf("Id de la conference a supprimer : ");
scanf("%d", &id); scanf("%d", &id);
removeConf(confChain, id); removeConf(confChain, id);
saveConf(confChain); saveConf(confChain->next);
saveRelations(confChain->next);
menuConf(confChain, listenerChain); menuConf(confChain, listenerChain);
break; break;
} }
@ -795,7 +780,7 @@ void menuConf(ptConf confChain, ptListener listenerChain)
} }
} }
saveConf(confChain); saveConf(confChain->next);
menuConf(confChain, listenerChain); menuConf(confChain, listenerChain);
} }
@ -815,6 +800,8 @@ void menuAbo(ptConf confChain, ptListener listenerChain)
system("cls"); system("cls");
drawMenu(options, 4); drawMenu(options, 4);
goToCoords(0, 12); goToCoords(0, 12);
tasse();
printf("\n");
printf("Que voulez-vous faire ? : "); printf("Que voulez-vous faire ? : ");
int choice; int choice;
scanf("%d", &choice); scanf("%d", &choice);
@ -823,14 +810,14 @@ void menuAbo(ptConf confChain, ptListener listenerChain)
{ {
case 1: case 1:
{ {
ptListener py = listenerChain; ptListener py = listenerChain->next;
while (py->next != NULL) while (py->next != NULL)
{ {
printf("Id : %d\nNom: %s\nAge: %d\nNiveau: %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) if (py->confs->next != NULL)
{ {
printConfList(py->confs); printConfList(py->confs->next);
} }
printf("\n"); printf("\n");
py = py->next; py = py->next;
@ -855,7 +842,7 @@ void menuAbo(ptConf confChain, ptListener listenerChain)
if (addListener(listenerChain, id, name, age, level) != -1) if (addListener(listenerChain, id, name, age, level) != -1)
{ {
saveListeners(listenerChain); saveListeners(listenerChain->next);
} }
else else
{ {
@ -868,13 +855,24 @@ void menuAbo(ptConf confChain, ptListener listenerChain)
case 3: 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; int id;
printf("Id de l'abonne a supprimer : "); printf("Id de l'abonne a supprimer : ");
scanf("%d", &id); scanf("%d", &id);
removeListener(listenerChain, id); removeListener(listenerChain, id);
saveListeners(listenerChain); saveListeners(listenerChain->next);
saveRelations(confChain->next);
menuAbo(confChain, listenerChain); menuAbo(confChain, listenerChain);
break; break;
} }
@ -912,6 +910,23 @@ void menu(ptConf confChain, ptListener listenerChain)
case 3: 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; int confId, listenerId, grade;
printf("Entrez l'ID de la conference : "); printf("Entrez l'ID de la conference : ");
scanf("%d", &confId); scanf("%d", &confId);
@ -922,7 +937,7 @@ void menu(ptConf confChain, ptListener listenerChain)
if (participateToConf(confChain, listenerChain, confId, listenerId, grade) != -1) if (participateToConf(confChain, listenerChain, confId, listenerId, grade) != -1)
{ {
saveRelations(confChain); saveRelations(confChain->next);
} }
else else
{ {