Ok guys, I know I'm really annoying posting questions every day, but this forum is my last chance to finish my university tasks. I have only 1 more day.
I need your help with a binary file.
The question is quite similar to one of my last posts.
I need to read a binary file like this:
Where the text before the # is the name of the player and the number after the # is the number of dice rolls that the player needed to win.cBoard#10
Bruce the boss#12
Darth Vader FTW#16
As you can see, all of they are ordered from the one with less dice rolls to the one with most dice rolls. And there are only 5 players, the TOP 5 players of all time.
After play the game, I have to compare the dice rolls from the winner with all that 5 players. If the winner needed less dice rolls than one of the other players, the program has to write the ranking again with the new order.
I'm using this code to read one line like "Darth Vader FTW#16":
And this one to write it on the file:Code:fread(strLinea, sizeof(char), 100, f);
jugador[i].strNom is the name of the winner.Code:strcpy(strAux,jugador[i].strNom);itoa(jugador[i].nTiradestotals,strTirades,2); strcat(strAux,"#"); strcat(strAux, strTirades); fwrite(strAux, sizeof(char), 100, f);
jugador[i].nTiradestotals is the number of dice rolls needed to win.
But I think I'm not doing it good, it doesn't work.
And I don't know how to read-compare-upload.
If you, guys, can help me, I will be eternally grateful.