commit
This commit is contained in:
parent
aa5045a797
commit
dec244496a
10 changed files with 148 additions and 76 deletions
|
@ -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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue