Alex.
Retired
- Joined
- Aug 24, 2005
- Messages
- 4,616
I need to save a single integer hiscore for this minigame I'm making in C and SDL. Here's a stripped down version of my code, which crashes the GP2X. Any help would be very much appreciated!
- Alex
Code:
#include <stdio.h>
typedef struct {
int hiscore;
} HISCORE;
HISCORE hiscore;
void gethiscore(void) {
FILE* f;
f = fopen("sqcolony", "rb");
if(!f) return;
fread(&hiscore,sizeof(HISCORE),1,f);
fclose(f);
}
void savehiscore(int score) {
if(score <= hiscore.hiscore) return;
hiscore.hiscore = score;
FILE* f;
f = fopen("sqcolony", "wb");
fwrite(&hiscore,sizeof(HISCORE),1,f);
fclose(f);
}
int main(int argc, char **argv) {
hiscore.hiscore = 0;
int score = 0;
gethiscore();
//
// gameloop
//
savehiscore(score);
}
- Alex