file create

Hi, i have created a game in c++ and i want some way of saving a highscore to a file and loading it when the game starts
all i want to do is, when the game first starts and there is no file called highscore.txt, save a 0. if it is there then just load the highscore thats in there

void filewrite(){

int n;

FILE *FPtr;
FPtr = fopen("highscore.txt","w+");//open file
if (FPtr == NULL){
fprintf (FPtr, "%d" , highscore);
rewind(FPtr);
}
fscanf(FPtr,"%d",&n);//scan file for integer


if (n < score){
if(highscore < score ){
if(end==true){
fprintf (FPtr, "%d" , score);//print the score to file if it is higher than the score already there
rewind(FPtr);//rewind the file, so pointer starts at begining
fscanf(FPtr,"%d",&highscore);//scan file for int
}
}
}

fclose(FPtr);//close pointer to file

}
this is my code
cheers for the help
What's the question?
Topic archived. No new replies allowed.