8 /* Open the highscore file: */
14 #include "high_scores.h"
16 FILE * opendata(char * mode)
24 /* Create the buffer for the filename: */
26 filename = (char *) malloc(sizeof(char) * (strlen(st_dir) +
27 strlen("/highscore") + 1));
29 strcpy(filename, st_dir);
30 /* Open the high score file: */
32 strcat(filename, "/highscore");
35 filename = "st_highscore.dat";
39 /* Try opening the file: */
41 fi = fopen(filename, mode);
45 fprintf(stderr, "Warning: I could not open the high score file ");
47 if (strcmp(mode, "r") == 0)
48 fprintf(stderr, "for read!!!\n");
49 else if (strcmp(mode, "w") == 0)
50 fprintf(stderr, "for write!!!\n");
57 /* Load data from high score file: */
65 /* Try to open file: */
72 fgets(temp, sizeof(temp), fi);
76 temp[strlen(temp) - 1] = '\0';
79 /* Parse each line: */
81 if (strstr(temp, "highscore=") == temp)
83 score = atoi(temp + 10);
97 void save_hs(int score)
102 /* Try to open file: */
107 fprintf(fi, "# Supertux highscore file\n\n");
109 fprintf(fi, "highscore=%d\n", score);
111 fprintf(fi, "# (File automatically created.)\n");