commit
This commit is contained in:
parent
c755619819
commit
63e83a9601
6 changed files with 153 additions and 85 deletions
|
@ -4,56 +4,45 @@
|
|||
#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;
|
||||
FILE *file = fopen("./data/confs", "r");
|
||||
char line[100];
|
||||
char *token;
|
||||
|
||||
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]));
|
||||
if (file == NULL) {
|
||||
printf("ça marche pas.");
|
||||
return;
|
||||
}
|
||||
|
||||
while (fgets(line, sizeof(line), file)) {
|
||||
int id = atoi(strtok(line, ","));
|
||||
char *title = strtok(NULL, ",");
|
||||
char *speaker = strtok(NULL, ",");
|
||||
int day = atoi(strtok(NULL, ","));
|
||||
int month = atoi(strtok(NULL, ","));
|
||||
int year = atoi(strtok(NULL, ","));
|
||||
|
||||
addConf(confChain, id, title, speaker, day, month, year);
|
||||
}
|
||||
|
||||
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;
|
||||
FILE *file = fopen("./data/listeners", "r");
|
||||
char line[100];
|
||||
char *token;
|
||||
|
||||
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]));
|
||||
if (file == NULL) {
|
||||
printf("ça marche pas.");
|
||||
return;
|
||||
}
|
||||
|
||||
while (fgets(line, sizeof(line), file)) {
|
||||
int id = atoi(strtok(line, ","));
|
||||
char *name = strtok(NULL, ",");
|
||||
int day = atoi(strtok(NULL, ","));
|
||||
int month = atoi(strtok(NULL, ","));
|
||||
addListener(listenerChain, id, name, day, month);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
@ -62,10 +51,8 @@ void readListeners(ptListener listenerChain) {
|
|||
void readRelations(ptConf confChain, ptListener listenerChain) {
|
||||
FILE *file = fopen("./data/relations", "r");
|
||||
char line[100];
|
||||
char *tokens[50];
|
||||
char *token;
|
||||
int i;
|
||||
int j;
|
||||
char *token1;
|
||||
char *token2;
|
||||
|
||||
if (file == NULL) {
|
||||
printf("ça marche pas.");
|
||||
|
@ -73,22 +60,13 @@ void readRelations(ptConf confChain, ptListener listenerChain) {
|
|||
}
|
||||
|
||||
while (fgets(line, sizeof(line), file)) {
|
||||
token = strtok(line, ":");
|
||||
printf("%d\n", atoi(token));
|
||||
int confId = atoi(strtok(line, ":"));
|
||||
|
||||
i = 0;
|
||||
|
||||
while (token != NULL) {
|
||||
tokens[i] = token;
|
||||
i ++;
|
||||
token = strtok(NULL, ",");
|
||||
while ((token1 = strtok(NULL, ";")) != NULL && (token2 = strtok(NULL, ",")) != NULL) {
|
||||
participateToConf(confChain, listenerChain, confId, atoi(token1), atoi(token2));
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 1; j < i; j++) {
|
||||
participateToConf(confChain, listenerChain, atoi(tokens[0]), atoi(tokens[j]));
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
|
@ -124,7 +102,7 @@ void saveRelations(ptConf confChain) {
|
|||
}
|
||||
|
||||
while (py -> next != NULL) {
|
||||
fprintf(file, "%d", py -> listener -> id);
|
||||
fprintf(file, "%d;%d", py -> listener -> id, py -> grade);
|
||||
if (py -> next -> next != NULL) {
|
||||
fprintf(file, ",");
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue