commit
This commit is contained in:
parent
df2be62fe2
commit
e015c4a017
3 changed files with 307 additions and 234 deletions
105
fileManager.c
105
fileManager.c
|
@ -3,17 +3,20 @@
|
|||
#include <string.h>
|
||||
#include "conf.h"
|
||||
|
||||
void readConfs(ptConf confChain) {
|
||||
void readConfs(ptConf confChain)
|
||||
{
|
||||
FILE *file = fopen("./data/confs", "r");
|
||||
char line[100];
|
||||
char *token;
|
||||
|
||||
if (file == NULL) {
|
||||
if (file == NULL)
|
||||
{
|
||||
printf("ça marche pas.");
|
||||
return;
|
||||
}
|
||||
|
||||
while (fgets(line, sizeof(line), file)) {
|
||||
while (fgets(line, sizeof(line), file))
|
||||
{
|
||||
int id = atoi(strtok(line, ","));
|
||||
char *title = strtok(NULL, ",");
|
||||
char *speaker = strtok(NULL, ",");
|
||||
|
@ -27,17 +30,20 @@ void readConfs(ptConf confChain) {
|
|||
fclose(file);
|
||||
}
|
||||
|
||||
void readListeners(ptListener listenerChain) {
|
||||
void readListeners(ptListener listenerChain)
|
||||
{
|
||||
FILE *file = fopen("./data/listeners", "r");
|
||||
char line[100];
|
||||
char *token;
|
||||
|
||||
if (file == NULL) {
|
||||
if (file == NULL)
|
||||
{
|
||||
printf("ça marche pas.");
|
||||
return;
|
||||
}
|
||||
|
||||
while (fgets(line, sizeof(line), file)) {
|
||||
while (fgets(line, sizeof(line), file))
|
||||
{
|
||||
int id = atoi(strtok(line, ","));
|
||||
char *name = strtok(NULL, ",");
|
||||
int day = atoi(strtok(NULL, ","));
|
||||
|
@ -48,21 +54,25 @@ void readListeners(ptListener listenerChain) {
|
|||
fclose(file);
|
||||
}
|
||||
|
||||
void readRelations(ptConf confChain, ptListener listenerChain) {
|
||||
FILE *file = fopen("./data/relations", "r");
|
||||
char line[100];
|
||||
char *token1;
|
||||
void readRelations(ptConf confChain, ptListener listenerChain)
|
||||
{
|
||||
FILE *file = fopen("./data/relations", "r");
|
||||
char line[100];
|
||||
char *token1;
|
||||
char *token2;
|
||||
|
||||
if (file == NULL) {
|
||||
printf("ça marche pas.");
|
||||
return;
|
||||
}
|
||||
|
||||
while (fgets(line, sizeof(line), file)) {
|
||||
|
||||
if (file == NULL)
|
||||
{
|
||||
printf("ça marche pas.");
|
||||
return;
|
||||
}
|
||||
|
||||
while (fgets(line, sizeof(line), file))
|
||||
{
|
||||
int confId = atoi(strtok(line, ":"));
|
||||
|
||||
while ((token1 = strtok(NULL, ";")) != NULL && (token2 = strtok(NULL, ",")) != NULL) {
|
||||
while ((token1 = strtok(NULL, ";")) != NULL && (token2 = strtok(NULL, ",")) != NULL)
|
||||
{
|
||||
participateToConf(confChain, listenerChain, confId, atoi(token1), atoi(token2));
|
||||
}
|
||||
}
|
||||
|
@ -70,50 +80,61 @@ void readRelations(ptConf confChain, ptListener listenerChain) {
|
|||
fclose(file);
|
||||
}
|
||||
|
||||
void saveConf(ptConf confChain) {
|
||||
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;
|
||||
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) {
|
||||
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;
|
||||
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) {
|
||||
void saveRelations(ptConf confChain)
|
||||
{
|
||||
FILE *file = fopen("./data/relations", "w");
|
||||
ptConf px = confChain;
|
||||
ptListenerList py;
|
||||
printf("test");
|
||||
while(px -> next != NULL){
|
||||
while (px->next != NULL)
|
||||
{
|
||||
printf("test");
|
||||
py = px -> listeners -> next;
|
||||
py = px->listeners->next;
|
||||
|
||||
if (py -> next != NULL) {
|
||||
fprintf(file, "%d:", px -> id);
|
||||
}
|
||||
|
||||
while (py -> next != NULL) {
|
||||
fprintf(file, "%d;%d", py -> listener -> id, py -> grade);
|
||||
if (py -> next -> next != NULL) {
|
||||
fprintf(file, ",");
|
||||
} else {
|
||||
fprintf(file, "\n");
|
||||
}
|
||||
py = py -> next;
|
||||
if (py->next != NULL)
|
||||
{
|
||||
fprintf(file, "%d:", px->id);
|
||||
}
|
||||
|
||||
px = px -> next;
|
||||
while (py->next != NULL)
|
||||
{
|
||||
fprintf(file, "%d;%d", py->listener->id, py->grade);
|
||||
if (py->next->next != NULL)
|
||||
{
|
||||
fprintf(file, ",");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(file, "\n");
|
||||
}
|
||||
py = py->next;
|
||||
}
|
||||
|
||||
px = px->next;
|
||||
}
|
||||
fclose(file);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue