FILE *dataScore;
dataScore = fopen(fileName.dat, "w");
fprintf(dataScore,"%s:%d\n",currentUser,score);
fclose(dataScore);
文件在打印到文件的行上崩溃。我相信这是由于用户名,但我可能是错的。提前致谢。将currentUser设置为02heasam并得分为20。
答案 0 :(得分:2)
看起来很疯狂......
尝试这种方式:
int score=20;
int main(void){
char* currentUser = "02heasam";
FILE *dataScore;
dataScore = fopen("fileName.dat", "w");
fprintf(dataScore,"%s:%d\n",currentUser,score);
fclose(dataScore);
}
一些解释: