fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define TEAM_SIZE 10
  5.  
  6. typedef struct {
  7. char name[TEAM_SIZE];
  8. int points;
  9. } TEAM;
  10.  
  11.  
  12. int compare_points(const void *a, const void *b)
  13. {
  14. const TEAM *p1 = a;
  15. const TEAM *p2 = b;
  16. return p2->points < p1->points ? -1 : p1->points < p2->points;
  17. }
  18.  
  19. int main()
  20. {
  21. TEAM teams[] =
  22. {
  23. { "OB", 46 }, { "AGF", 37 },
  24. { "AAB", 50 }, { "FCK", 71 },
  25. { "HOB", 18 }, { "SDR", 62 },
  26. { "RFC", 47 }, { "BIF", 54 },
  27. { "EFB", 30 }, { "VFF", 40 }
  28. };
  29.  
  30. size_t NUM_TEAMS = sizeof teams / sizeof *teams;
  31.  
  32. qsort(teams, NUM_TEAMS, sizeof(TEAM), compare_points);
  33.  
  34. for (size_t i=0; i< NUM_TEAMS; ++i)
  35. printf("%s : %d\n", teams[i].name, teams[i].points);
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
FCK : 71
SDR : 62
BIF : 54
AAB : 50
RFC : 47
OB : 46
VFF : 40
AGF : 37
EFB : 30
HOB : 18