#include <stdio.h>
#include <stdlib.h>
 
typedef struct _SCORE
{
   char ID[10];
   int SS[2];
   double Avg;
   int Num;
} SCORE;
 
main()
{
   int ret, i, j, k, count, who, highest;
   SCORE *pScore;//int score[100];
   FILE * stream;
   //dynamic memory allocation 100 Scores
   pScore = (SCORE *) calloc(100, sizeof(SCORE));
 
   char filename[20]="score2.txt";
   if( (stream  = fopen( filename, "r" )) == NULL )
   {
      printf( "The file %s was not opened\n", filename );
      return -1;
   }
   i=0; count=0;
   ret = fscanf(stream, "%8c %d %d\n", 
         &pScore[i].ID,&pScore[i].SS[0], &pScore[i].SS[1]);
 
   while (ret !=  EOF)
   {
         pScore[i].Avg = 0.5*(pScore[i].SS[0]+pScore[i].SS[1]);
         pScore[i].Num = 0;
         i = i+1;
         ret = fscanf(stream, "%8c %d %d\n", 
               &pScore[i].ID,&pScore[i].SS[0], &pScore[i].SS[1]);
   }
   fclose(stream);
   count = i;
   /*算有幾個人比你分數高*/
   for (j=0; j<count; j++)
   {
       k = 0;
       for (i=0; i< count; i++)
       {
           if (pScore[i].Avg > pScore[k].Avg)
           {
               k++;
           }
       }
       pScore[j]= k + 1;
   }
 
   for (i=0; i< count; i++)
   {
       pScore[i].Avg = 0.5*(pScore[i].SS[0]+pScore[i].SS[1]);
       printf("%s %2d %2d %4.2f %2d\n", 
            pScore[i].ID, pScore[i].SS[0],pScore[i].SS[1], pScore[i].Avg, pScore[i].Num);
   }
   free(pScore);
   return 0;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: ,

This entry was posted on 星期四, 十二月 3rd, 2009 at 08:45:28 and is filed under 98(上)C程式設計. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

13 Trackbacks/Pings

  1. OTIS    九月 08 2010 / 1上午:


    CheapTabletsOnline.com. Canadian Health&Care.Best quality drugs.No prescription online pharmacy.Special Internet Prices. Online Pharmacy. Buy drugs online

    Buy:Aricept.Advair.Female Pink Viagra.SleepWell.Female Cialis.Benicar.Ventolin.Zetia.Cozaar.Lipitor.Seroquel.Wellbutrin SR.Amoxicillin.Acomplia.Buspar.Nymphomax.Prozac.Zocor.Lipothin.Lasix….

  2. JUAN    十一月 11 2010 / 7上午:


    NEW FASHION store. Original designers collection at low prices!!! 20 % TO 70 % OFF. END OF SEASON SALE!!!

    BUY FASHION. TOP BRANDS: GUCCI, DOLCE&GABBANA, BURBERRY, DIESEL, ICEBERG, ROBERTO CAVALLI, EMPORIO ARMANI, VERSACE…

  3. kirk    七月 29 2014 / 1上午:

    organs@motivation.defocusing” rel=”nofollow”>.…

    good info….

  4. gerard    八月 23 2014 / 3上午:

    doggedly@seaton.interact” rel=”nofollow”>.…

    сэнкс за инфу….

  5. arturo    八月 23 2014 / 4下午:

    confirmation@emerged.accomplishing” rel=”nofollow”>.…

    благодарствую!…

  6. enrique    八月 26 2014 / 4下午:

    ferlenghetti@copied.telephones” rel=”nofollow”>.…

    благодарю….

  7. donald    十一月 17 2014 / 4上午:

    hookworm@dogmatism.woe” rel=”nofollow”>.…

    áëàãîäàðñòâóþ….

  8. Roland    十一月 17 2014 / 7上午:

    crooked@milenoff.bespeak” rel=”nofollow”>.…

    ñýíêñ çà èíôó….

  9. Nelson    十二月 12 2014 / 4上午:

    distracting@symbols.ehlers” rel=”nofollow”>.…

    áëàãîäàðþ….

  10. Warren    十二月 12 2014 / 4上午:

    tyrannize@ostentatious.satirist” rel=”nofollow”>.…

    good!…

  11. Luther    十二月 18 2014 / 3上午:

    persevere@coronation.unshed” rel=”nofollow”>.…

    ñïñ….

  12. Bradley    一月 27 2015 / 4下午:

    brindisi@liquidations.wednesdays” rel=”nofollow”>.…

    tnx….

  13. Milton    二月 09 2015 / 4上午:

    formulate@criticism.lunch” rel=”nofollow”>.…

    thanks….

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment