Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <locale.h>
- #include <string.h>
- int main()
- {
- system("chcp 1251");
- setlocale(LC_ALL, "rus");
- FILE* F;
- F = fopen("Names.txt", "rt");
- if (F == NULL)
- {
- printf("NO FILE");
- return 0;
- }
- struct humen
- {
- char firstn[100];
- char secondn[100];
- int birth;
- };
- struct humen sort[100];
- char a = 0;
- while (fscanf(F, "%s %s %d", sort[a].firstn, sort[a].secondn, &sort[a].birth) != EOF)
- {
- a++;
- }
- struct humen s;
- for (int i = 0; i < a; i++)
- {
- for (int j = a - 1; j >= i; j--)
- {
- if (sort[j - 1].birth > sort[j].birth)
- {
- s = sort[j - 1];
- sort[j - 1] = sort[j];
- sort[j] = s;
- }
- }
- }
- for (int i = 0; i < a; i++)
- {
- printf("%s %s %d\n", sort[i].firstn, sort[i].secondn, sort[i].birth);
- }
- fclose(F);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement