I cannot sort the list according to the ordering:

1 вратари; 2 защитники; 3 полузащитники; 4 нападающие; 

Sort need to method of minimum-maximum.
There is a structure

 struct football { char surname[N]; char nation[N]; int age; int height; int weight; char amplua[N]; char country[N]; } player[11]; 

The indicated categories are recorded in the file in the amplua column.

 #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<string.h> #include<malloc.h> #include<locale.h> #define N 50 struct football { char surname[N]; char nation[N]; int age; int height; int weight; char amplua[N]; char country[N]; }player[11],flag; int main () { int i=0, max, index; setlocale(LC_ALL, "Rus"); FILE* f; struct football *record = malloc(sizeof(struct football)); if ((f = fopen("record.txt", "r"))==NULL) { printf("error"); } else { while (!feof(f)) { fscanf(f,"%s", player[i].surname); fscanf(f,"%s", &player[i].nation); fscanf(f,"%d", &player[i].age); fscanf(f,"%d", &player[i].height); fscanf(f,"%d", &player[i].weight); fscanf(f,"%s", &player[i].amplua); fscanf(f,"%s", &player[i].country); i++; } printf("+----------+-----------+----+-----+----+--------------+-----------+\n"); printf("| Фамилия |Гражданство|Возр| Рост| Вес| Амплуа |Где играет |\n"); printf("+----------+-----------+----+-----+----+--------------+-----------+\n"); for (int i = 0; i < 11; i++) { printf("|%9s | %9s | %2d | %3d | %2d | %12s | %9s |\n", player[i].surname, player[i].nation, player[i].age, player[i].height, player[i].weight, player[i].amplua, player[i].country); } printf("+----------+-----------+----+-----+----+--------------+-----------+\n"); max = player[0].height; index = 0; for (int i = 0; i<11; i++) { if (V(player[i].amplua) &&(max<player[i].height)) { max = player[i].height; index = i; } } printf("\nСамый высокий вратарь - %s;\n", player[index].surname); printf("Футболисты , которые играют не в своей стране:\n"); for (int i = 0; i < 11; i++) { if (!Nation(player[i].nation,player[i].country)) { printf("-%s;\n", player[i].surname); } }for (int i = 0; i < 11; i++) { if (Sort()) printf("|%9s | %9s | %2d | %3d | %2d | %12s | %9s |\n", player[i].surname, player[i].nation, player[i].age, player[i].height, player[i].weight, player[i].amplua, player[i].country); } } free(record); fclose(f); _getch(); return 0; } int V(char amplua[]) { int i; char v[] = "вратарь"; if (strlen(amplua) != strlen(v)) return 0; for (i = 0; i < strlen(amplua); i++) if (amplua[i] != v[i]) return 0; return 1; } int Nation(char nation[],char county[]) { for (int i = 0; i < 11; i++) if (nation[i] != county[i]) return 0; } int Vr(char amplua[]) { int i; char v[] = "вратарь"; if (strlen(amplua) != strlen(v)) return 0; for (i = 0; i < strlen(amplua); i++) if (amplua[i] != v[i]) return 0; } int Z(char amplua[]) { int i; char z[] = "защитник"; if (strlen(amplua) != strlen(z)) return 0; for (i = 0; i < strlen(amplua); i++) if (amplua[i] != z[i]) return 0; amplua[i] = 2; } int PZ(char amplua[]) { int i; char p[] = "полузащитник"; if (strlen(amplua) != strlen(p)) return 0; for (i = 0; i < strlen(amplua); i++) if (amplua[i] != p[i]) return 0; amplua[i] = 3; } int NP(char amplua[]) { int i; char n[] = "нападающий"; if (strlen(amplua) != strlen(n)) return 0; for (i = 0; i < strlen(amplua); i++) if (amplua[i] != n[i]) return 0; amplua[i] = 4; } int Sort() { int i = 0; Vr(player[i].amplua); Z(player[i].amplua); PZ(player[i].amplua); NP(player[i].amplua); for (int i = 0; i < 11; i++) { int min = player[i].amplua; int minIndex = i; for (int j = i + 1; j < 11; j++) { if (player[i].amplua < min) { min = player[j].amplua; minIndex = j; flag = player[i]; player[i] = player[minIndex]; player[minIndex] = flag; } } printf("|%9s | %9s | %2d | %3d | %2d | %12s | %9s |\n", player[i].surname, player[i].nation, player[i].age, player[i].height, player[i].weight, player[i].amplua, player[i].country); } } 

I tried to assign numbers so that I ordered something. Sorts nothing. And this method can not find.

  • It is advisable to remove from the code everything that is not relevant to the topic. You ask about min-max sorting, and the code also reads from a file, searches for the highest goalkeeper, etc. - HolyBlackCat
  • You have several places in the code where the body of if missing, for example, in Nation() . In addition, in Z() and elsewhere, there is code after return that will never be executed. Also, at the beginning of the Sort() calls Vr , Z , PZ , NP do nothing. Still, although this does not apply to sorting, while (!feof(f)) does not do what you think, more in detail here . - HolyBlackCat
  • Thanks for the answer) So, what to do with sorting? How to sort by this method? - user298646
  • There seems to be code here: stackoverflow.com/questions/41667225/… - HolyBlackCat
  • Isn't it easier to use sorting by count? ru.wikipedia.org/wiki/… - SOCIOPATH

0