conf-database/conf.c
2023-11-20 14:42:20 +01:00

86 lines
No EOL
1.8 KiB
C

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "conf.h"
int findConfId(ptConf confChain) {
ptConf px = confChain;
int max = 0;
while (px -> next != NULL) {
if (px -> id > max) {
max = px -> id;
}
px = px -> next;
}
return max + 1;
}
ptConf newConfChain() {
ptConf confChain = (ptConf) malloc(sizeof(tConf));
confChain -> next = NULL;
return confChain;
}
void addConf(ptConf confChain, char title[], char speaker[], int day, int month, int year) {
ptConf px = confChain;
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;
}
int findListenerId(ptListener listenerChain) {
ptListener px = listenerChain;
int max = 0;
while (px -> next != NULL) {
if (px -> id > max) {
max = px -> id;
}
px = px -> next;
}
return max + 1;
}
ptListener newListenerChain() {
ptListener listenerChain = (ptListener) malloc(sizeof(tListener));
listenerChain -> prev = NULL;
listenerChain -> next = NULL;
return listenerChain;
}
void addListener(ptListener listenerChain, char name[], int age, int level) {
ptListener px = listenerChain;
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;
}