-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.c
47 lines (41 loc) · 820 Bytes
/
file.c
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <stdlib.h>
#include "file.h"
#include "linklist.h"
node *first;
FILE *f;
char username[20];
char password[20];
int status, win, lose;
node *s1;
void readFile()
{
f = fopen("account.txt", "rt");
if (f == NULL)
{
perror("Error while opening the file.\n");
exit(EXIT_FAILURE);
}
else
{
while (1)
{
if (fscanf(f, "%s %s %d %d %d", username, password, &status, &win, &lose) == EOF)
break;
s1 = initLinkList(s1, username, password, status, win, lose);
}
fclose(f);
}
}
void writeFile()
{
node *temp = first;
remove("account.txt");
f = fopen("account.txt", "w");
while (temp)
{
fprintf(f, "%s %s %d %d %d\n", temp->username, temp->password, temp->status, temp->win, temp->lose);
temp = temp->next;
}
fclose(f);
}