This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 20th, 2011  |  syntax: C  |  size: 1.85 KB  |  views: 69  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. void showScoreboard(Player player[])
  2. {
  3.     FILE *scoreboardFile = fopen("scoreboard.txt", "r");
  4.     int i;
  5.  
  6.     /*system("CLS");*/
  7.  
  8.     /*READ SCORES FROM TEXTFILE*/
  9.     for(i=0; i<MAX && !feof(scoreboardFile); i++)
  10.     {
  11.         fscanf(scoreboardFile, "%s %d", player[i].name, &player[i].points);
  12.  
  13.         printf("name: %s, points: %d\n\n\n", player[i].name, player[i].points);
  14.     }
  15.     printf("\n\n\n");
  16.     system("pause");
  17.  
  18.     fclose(scoreboardFile);
  19. }
  20.  
  21. void sortScoreboard(Player player[])
  22. {
  23.     int i,j,tempPoints;
  24.     char tempName[20];
  25.     int howMany=0;
  26.     FILE *scoreboardFile = fopen("scoreboard.txt", "r");
  27.  
  28.     /*READ SCORES FROM TEXTFILE*/
  29.     for(i=0; i<MAX && !feof(datafil) ; i++)
  30.     {
  31.         fscanf(scoreboardFile, "%s %d", player[i].name, &player[i].points);
  32.         printf("name: %s, points: %d\n", player[i].name, player[i].points);
  33.         howMany++;
  34.     }
  35.     printf("\n\n\nhow many: %d\n\n\n",howMany);
  36.  
  37.     /*SORT WITH BUBBLESORT*/
  38.     for(i=0; i<howMany; i++)
  39.     {
  40.         for(j=0; j<howMany-1; j++)
  41.         {
  42.             if(player[i].points > player[i+1].points)
  43.             {
  44.                 tempPoints = player[i].points;
  45.                 /*tempName = player[i].name;*/
  46.  
  47.                 player[i].points = player[i+1].points;
  48.                 /*player[i].name = player[i+1].name;*/
  49.  
  50.                 player[i+1].points = tempPoints;
  51.                 /*player[i+1].name = tempName;*/
  52.             }
  53.         }
  54.     }
  55.  
  56.     fclose(scoreboardFile);
  57.     FILE *scoreboardFile2 = fopen("scoreboard.txt", "w");
  58.     void rewind ( FILE * scoreboardFile2 );
  59.  
  60.     /*WRITE SORTED SCORES TO TEXTFILE*/
  61.     for(i=0; i<antal; i++)
  62.     {
  63.         printf("%s %d\n", player[i].name, player[i].points);
  64.         fprintf(scoreboardFile2, "%s %d\n\n\n", player[i].name, player[i].points);
  65.     }
  66.  
  67.     fclose(scoreboardFile2);
  68. }
clone this paste RAW Paste Data