diff --git a/fileManager.c b/fileManager.c index a6e71fb..1752ac6 100644 --- a/fileManager.c +++ b/fileManager.c @@ -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; diff --git a/fileManager.h b/fileManager.h index a85a8e3..0c967e4 100644 --- a/fileManager.h +++ b/fileManager.h @@ -4,6 +4,7 @@ #include "conf.h" void readConfs(ptConf confChain); +void readListeners(ptListener listenerChain); void saveConf(ptConf confChain); void saveListeners(ptListener listenerChain); diff --git a/main.c b/main.c index e61ade7..d09b600 100644 --- a/main.c +++ b/main.c @@ -10,9 +10,12 @@ int main() ptListener listenerChain = newListenerChain(); readConfs(confChain); + readListeners(listenerChain); + menu(confChain, listenerChain); + saveConf(confChain); saveListeners(listenerChain); - + return 0; } \ No newline at end of file