Advertisement
_who___

LAB7

May 5th, 2023
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <locale.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7. system("chcp 1251");
  8. setlocale(LC_ALL, "rus");
  9. FILE* F;
  10. F = fopen("Names.txt", "rt");
  11.  
  12. if (F == NULL)
  13. {
  14. printf("NO FILE");
  15. return 0;
  16. }
  17.  
  18. struct humen
  19. {
  20. char firstn[100];
  21. char secondn[100];
  22. int birth;
  23. };
  24.  
  25. struct humen sort[100];
  26. char a = 0;
  27.  
  28. while (fscanf(F, "%s %s %d", sort[a].firstn, sort[a].secondn, &sort[a].birth) != EOF)
  29. {
  30. a++;
  31. }
  32.  
  33. struct humen s;
  34. for (int i = 0; i < a; i++)
  35. {
  36. for (int j = a - 1; j >= i; j--)
  37. {
  38. if (sort[j - 1].birth > sort[j].birth)
  39. {
  40. s = sort[j - 1];
  41. sort[j - 1] = sort[j];
  42. sort[j] = s;
  43. }
  44. }
  45. }
  46. for (int i = 0; i < a; i++)
  47. {
  48. printf("%s %s %d\n", sort[i].firstn, sort[i].secondn, sort[i].birth);
  49. }
  50. fclose(F);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement