Advertisement
Guest User

nawshad

a guest
May 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5.  
  6. struct Player
  7. {
  8. char name[100];
  9. char club[200];
  10. int goal;
  11. int assist;
  12.  
  13. };
  14. void swap(struct Player &p1,struct Player &p2)
  15. {
  16. struct Player temp=p1;
  17. p1=p2;
  18. p2=temp;
  19. }
  20.  
  21. void srt(struct Player p[],int n)
  22. {
  23. for(int i=0;i<n;i++)
  24. for(int j=0;j<n-i-1;j++)
  25. if(strcmp(p[j].club,p[j+1].club)>0)
  26. swap(p[j],p[j+1]);
  27. else if(strcmp(p[j].club,p[j+1].club)==0)
  28. if(p[j].goal<p[j+1].goal)
  29. swap(p[j],p[j+1]);
  30. }
  31.  
  32. int main()
  33. {
  34. struct Player player[15];
  35. FILE *f1;
  36. if((f1=fopen("players.txt","r"))==NULL)
  37. {
  38. printf("Error\n");
  39. exit(1);
  40. }
  41. for(int i=0;i<15;i++)
  42. {
  43.  
  44. if(fgets(player[i].name,99,f1)==NULL)
  45. {
  46.  
  47. if(ferror(f1)!=0)
  48. {
  49. printf("Error!");
  50. exit(1);
  51. }
  52. }
  53.  
  54. if(fgets(player[i].club,199,f1)==NULL)
  55. {
  56. if(ferror(f1)!=0)
  57. {
  58. printf("Error!");
  59. exit(1);
  60. }
  61. }
  62.  
  63. if(fscanf(f1,"%d %d\n",&player[i].goal,&player[i].assist)==NULL)
  64. {
  65. if(ferror(f1)!=0)
  66. {
  67. printf("Error!");
  68. exit(1);
  69. }
  70. }
  71.  
  72.  
  73. }
  74. srt(player,15);
  75. for(int i=0;i<15;i++)
  76. {
  77.  
  78. printf("%s%s%d %d\n\n",player[i].name,player[i].club,player[i].goal,player[i].assist);
  79. }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement