8 /* Open the highscore file: */
14 #include "high_scores.h"
16 FILE * opendata(char * mode)
22 filename = (char *) malloc(sizeof(char) * (strlen(st_dir) +
23 strlen("/st_highscore.dat") + 1));
25 strcpy(filename, st_dir);
26 /* Open the high score file: */
29 strcat(filename, "/highscore");
32 strcat(filename, "/st_highscore.dat");
37 /* Try opening the file: */
39 fi = fopen(filename, mode);
44 fprintf(stderr, "Warning: I could not open the high score file ");
46 if (strcmp(mode, "r") == 0)
47 fprintf(stderr, "for read!!!\n");
48 else if (strcmp(mode, "w") == 0)
49 fprintf(stderr, "for write!!!\n");
56 /* Load data from high score file: */
64 /* Try to open file: */
71 fgets(temp, sizeof(temp), fi);
75 temp[strlen(temp) - 1] = '\0';
78 /* Parse each line: */
80 if (strstr(temp, "highscore=") == temp)
82 score = atoi(temp + 10);
96 void save_hs(int score)
101 /* Try to open file: */
106 fprintf(fi, "# Supertux highscore file\n\n");
108 fprintf(fi, "highscore=%d\n", score);
110 fprintf(fi, "# (File automatically created.)\n");