I have a program that is operating now, it pulls scores from a text file. Which I want it to the scores are from the MLB AL Central Division it then multiplies wins by 2 points and assigns a score to the leader and prints all info to the screen. I need to have it put in order and then saved to a new txt file. Right now I have it saving the final team without being sorted just looking for a nudge in the right direction to achieve my goal. Thanks

Code:

Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main(void)

{
struct records {
     char filename;
     char team[50];
     int wins;
     int tie;
     int loss;
     int points;
 };
struct records roster;
     FILE*ifp = NULL;
     FILE*afd = NULL;
     constint argv;
     char filename2[64]={0};
     char filename[64]={0};
     int points;
     int points2;
     int total;


     printf("\nPlease enter the the .txt file you would like to open: ");
     scanf("%63s", filename);
     printf("Opened file name %s",filename);
     ifp = fopen(filename,"r");


            if(ifp == NULL)
     {
            printf("Could not open");
            printf("\nPlease enter the the .txt file you would like to open: 
            ");
            scanf("%63s", filename);
            printf("Opened file name %s",filename);
            ifp = fopen(filename,"r");
     }

     {
        printf("\nReading the file %s \n", ifp);
        while(fscanf(ifp,"%s %d %d %d", roster.team,&roster.wins, 
        &roster.loss,&roster.tie)!= EOF)
        printf("%s Wins:%d Losses:%d ties:%d total league points:%d\n", 
       roster.team, roster.wins, roster.loss, roster.tie,(roster.wins *2+ 
       roster.tie *1), total);
     }
        printf("closing %s", filename);
        fclose(ifp);

        printf("\nPlease enter the the .txt file you would like to write to: 
        ");
        scanf("%63s", filename2);
        printf("Opened file name %s",filename2);
        afd = fopen(filename2,"a+");

            if(afd == NULL)
    {
            printf("Could not open");
            printf("\nPlease enter the the .txt file you would like to open: 
            ");
            scanf("%63s", filename2);
            printf("Opened file name %s",filename2);
            afd = fopen(filename2,"a+");
      }
        points = roster.wins *2;
        points2 = roster.tie *1; 
        total = points + points2;   
        afd = fopen(filename2,"a+");
        fprintf(afd,"%s %d %d %d %d\n", roster.team, roster.wins, 
        roster.loss, roster.tie, total);
        printf("\nThanksfor your data 
        entry!\nClosing%s", filename2);
        fclose(afd);

        return0;
    }