-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHandleFiles.c
More file actions
33 lines (29 loc) · 848 Bytes
/
HandleFiles.c
File metadata and controls
33 lines (29 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "HandleFiles.h"
#include "Player.h"
#include "PlayersList.h"
#include "stringHandling.h"
#include "CStream.h"
#include <stdio.h>
#include <stdlib.h>
const char FILE_PATH[] = "list.f";
void savePlayer(CStream stream, Player player) {
fprintf(stream, "%s %d\n", getPlayerName(player), getPlayerScore(player));
}
void saveListPlayers(Node list) {
CStream handleFile = openFile(FILE_PATH, "w");
Node iterator;
for(iterator = list; iterator != NULL; iterator = iterator->next)
savePlayer(handleFile, iterator->player);
closeFile(handleFile);
}
Node getListPlayers(void) {
CStream handleFile = openFile(FILE_PATH, "r");
Node list = newPlayersList();
char name[101];
int score;
while(fscanf(handleFile, "%s %d", name, &score) != EOF) {
list = addSorted(list, _newPlayer(name, score));
}
closeFile(handleFile);
return list;
}