#include #include #include #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 readListeners(ptListener listenerChain) { FILE *file = fopen("./data/listeners", "r"); char line[100]; char *tokens[4]; 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 < 4) { tokens[i] = token; i ++; token = strtok(NULL, ","); } addListener(listenerChain, atoi(tokens[0]), tokens[1], atoi(tokens[2]), atoi(tokens[3])); } 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); } void saveRelations(ptConf confChain) { FILE *file = fopen("./data/relations", "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); }