52 lines
No EOL
1.2 KiB
C
52 lines
No EOL
1.2 KiB
C
#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, atoi(tokens[0]), 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);
|
|
} |