Hi all,
I've got a question about typdef.
I want to save highscores for my schoolproject and I want to do it with a typedef.
My program writes the highscores to a binairy file, but I don't know how to continue with the typedef...Code:typedef struct { char name[20]; int hs; } HS; HS highscore[4];
I tried the following already:
I also don't understand qsort, I don't know how to write a comparison that works for typedef.Code:if((f = fopen("hs.bin","rb")) == NULL) { strcpy(highscore[0].name, plyr_nm); highscore[0].hs = score; f = fopen("hs.bin", "wb"); length = strlen(highscore); fwrite(&length, 1,sizeof(int),f); fwrite(&highscore, length+1, sizeof(HS), f); fclose(f); } else { fopen("hs.bin", "rb"); fread(&length, sizeof(int),1,f); fread(&highscore, sizeof(char),length+1,f); fclose(f); strcpy(highscore[4].name, plyr_nm); highscore[4].hs = score; //than sort with qsort and write it back into the file }
Can someone help me out please?
Greetings!



LinkBack URL
About LinkBacks



