Advertisement
Vladislav8653

Untitled

Nov 20th, 2023
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. void input (char groups[15][7], char path[10], FILE *file, int start)
  6. {
  7. file = fopen(path, "r");
  8. int finish = start + 5;
  9. while (start < finish){
  10. fscanf(file, "%s", groups[start]);
  11. start++;
  12. }
  13. fclose(file);
  14. }
  15.  
  16. void output (char groups[15][7], char message[20])
  17. {
  18. printf("%s\n", message);
  19. int i = 0;
  20. while (i < 15){
  21. printf("%s\n",groups[i]);
  22. i++;
  23. }
  24. }
  25.  
  26. void sortArrayBubble (char groups[15][7])
  27. {
  28. const int N = 15;
  29. char temp[7];
  30. for (int i = 0; i < N - 1; i++){
  31. for (int j = i; j < N; j++){
  32. if (groups[i] > groups[j]){
  33. strcpy(temp, groups[i]);
  34. strcpy(groups[i], groups[j]);
  35. strcpy(groups[j], temp);
  36. }
  37. }
  38. }
  39. }
  40.  
  41. int main() {
  42. FILE *F1 = NULL;
  43. char groups[15][7];
  44. char path[7] = "F1.txt";
  45. input(groups, path, F1, 0);
  46. strcpy(path, "F2.txt");
  47. input(groups, path, F1, 5);
  48. strcpy(path, "F3.txt");
  49. input(groups, path, F1, 10);
  50. output(groups, "Virgin array:");
  51. printf("--------------------------------\n");
  52. int i, j;
  53. char cur[7];
  54. for(i=0;i<14;i++) {
  55. for (j = i + 1; j < 15; j++) {
  56. if (strcmp(groups[i], groups[j]) > 0) {
  57. strcpy(cur, groups[i]);
  58. strcpy(groups[i], groups[j]);
  59. strcpy(groups[j], cur);
  60. }
  61. }
  62. }
  63. //sortArrayBubble(groups);
  64. output(groups, "Sorted array:");
  65. return 0;
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement