Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- struct Player
- {
- char name[100];
- char club[200];
- int goal;
- int assist;
- };
- void swap(struct Player &p1,struct Player &p2)
- {
- struct Player temp=p1;
- p1=p2;
- p2=temp;
- }
- void srt(struct Player p[],int n)
- {
- for(int i=0;i<n;i++)
- for(int j=0;j<n-i-1;j++)
- if(strcmp(p[j].club,p[j+1].club)>0)
- swap(p[j],p[j+1]);
- else if(strcmp(p[j].club,p[j+1].club)==0)
- if(p[j].goal<p[j+1].goal)
- swap(p[j],p[j+1]);
- }
- int main()
- {
- struct Player player[15];
- FILE *f1;
- if((f1=fopen("players.txt","r"))==NULL)
- {
- printf("Error\n");
- exit(1);
- }
- for(int i=0;i<15;i++)
- {
- if(fgets(player[i].name,99,f1)==NULL)
- {
- if(ferror(f1)!=0)
- {
- printf("Error!");
- exit(1);
- }
- }
- if(fgets(player[i].club,199,f1)==NULL)
- {
- if(ferror(f1)!=0)
- {
- printf("Error!");
- exit(1);
- }
- }
- if(fscanf(f1,"%d %d\n",&player[i].goal,&player[i].assist)==NULL)
- {
- if(ferror(f1)!=0)
- {
- printf("Error!");
- exit(1);
- }
- }
- }
- srt(player,15);
- for(int i=0;i<15;i++)
- {
- printf("%s%s%d %d\n\n",player[i].name,player[i].club,player[i].goal,player[i].assist);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement