Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void showScoreboard(Player player[])
- {
- FILE *scoreboardFile = fopen("scoreboard.txt", "r");
- int i;
- /*system("CLS");*/
- /*READ SCORES FROM TEXTFILE*/
- for(i=0; i<MAX && !feof(scoreboardFile); i++)
- {
- fscanf(scoreboardFile, "%s %d", player[i].name, &player[i].points);
- printf("name: %s, points: %d\n\n\n", player[i].name, player[i].points);
- }
- printf("\n\n\n");
- system("pause");
- fclose(scoreboardFile);
- }
- void sortScoreboard(Player player[])
- {
- int i,j,tempPoints;
- char tempName[20];
- int howMany=0;
- FILE *scoreboardFile = fopen("scoreboard.txt", "r");
- /*READ SCORES FROM TEXTFILE*/
- for(i=0; i<MAX && !feof(datafil) ; i++)
- {
- fscanf(scoreboardFile, "%s %d", player[i].name, &player[i].points);
- printf("name: %s, points: %d\n", player[i].name, player[i].points);
- howMany++;
- }
- printf("\n\n\nhow many: %d\n\n\n",howMany);
- /*SORT WITH BUBBLESORT*/
- for(i=0; i<howMany; i++)
- {
- for(j=0; j<howMany-1; j++)
- {
- if(player[i].points > player[i+1].points)
- {
- tempPoints = player[i].points;
- /*tempName = player[i].name;*/
- player[i].points = player[i+1].points;
- /*player[i].name = player[i+1].name;*/
- player[i+1].points = tempPoints;
- /*player[i+1].name = tempName;*/
- }
- }
- }
- fclose(scoreboardFile);
- FILE *scoreboardFile2 = fopen("scoreboard.txt", "w");
- void rewind ( FILE * scoreboardFile2 );
- /*WRITE SORTED SCORES TO TEXTFILE*/
- for(i=0; i<antal; i++)
- {
- printf("%s %d\n", player[i].name, player[i].points);
- fprintf(scoreboardFile2, "%s %d\n\n\n", player[i].name, player[i].points);
- }
- fclose(scoreboardFile2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement