This commit is contained in:
Lukian 2023-11-20 17:54:34 +01:00
parent 7ae2a6982e
commit 8cb20fda51
3 changed files with 33 additions and 1 deletions

View file

@ -31,6 +31,34 @@ void readConfs(ptConf confChain) {
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;

View file

@ -4,6 +4,7 @@
#include "conf.h"
void readConfs(ptConf confChain);
void readListeners(ptListener listenerChain);
void saveConf(ptConf confChain);
void saveListeners(ptListener listenerChain);

5
main.c
View file

@ -10,9 +10,12 @@ int main()
ptListener listenerChain = newListenerChain();
readConfs(confChain);
readListeners(listenerChain);
menu(confChain, listenerChain);
saveConf(confChain);
saveListeners(listenerChain);
return 0;
}