-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.c
More file actions
56 lines (51 loc) · 1022 Bytes
/
file.c
File metadata and controls
56 lines (51 loc) · 1022 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "game.h"
#include "settings.h"
extern settings gameSet; // defined in settings.c
extern stat gameStat; // defined in settings.c
typedef struct {
settings set;
stat points;
} content;
void writeSettings(void){
FILE *fp;
content new;
new.set = gameSet;
new.points = gameStat;
if ( (fp = fopen(PATH,"wb")) != NULL ){
fwrite(&new,sizeof(content),1,fp);
fclose(fp);
}
}
void newSettings(void){
FILE *fp;
content new;
new.set = gameSet;
new.points = gameStat;
if ( (fp = fopen(PATH,"wb")) == NULL ){
printf("Error! Cant open game file");
return;
}
fwrite(&new,sizeof(content),1,fp);
fclose(fp);
}
void readSettings(void){
FILE *fp;
int x;
content new;
new.set = gameSet;
new.points = gameStat;
if ( (fp = fopen(PATH,"rb")) == NULL ){
// applyDefault();
newSettings();
} else {
x = (int)fread(&new,sizeof(content),1,fp);
if ( x == 0){
printf("Error Occurred\n");
applyDefault();
newSettings();
}
gameSet = new.set;
gameStat = new.points;
fclose(fp);
}
}