Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- void input (char groups[15][7], char path[10], FILE *file, int start)
- {
- file = fopen(path, "r");
- int finish = start + 5;
- while (start < finish){
- fscanf(file, "%s", groups[start]);
- start++;
- }
- fclose(file);
- }
- void output (char groups[15][7], char message[20])
- {
- printf("%s\n", message);
- int i = 0;
- while (i < 15){
- printf("%s\n",groups[i]);
- i++;
- }
- }
- void sortArrayBubble (char groups[15][7])
- {
- const int N = 15;
- char temp[7];
- for (int i = 0; i < N - 1; i++){
- for (int j = i; j < N; j++){
- if (groups[i] > groups[j]){
- strcpy(temp, groups[i]);
- strcpy(groups[i], groups[j]);
- strcpy(groups[j], temp);
- }
- }
- }
- }
- int main() {
- FILE *F1 = NULL;
- char groups[15][7];
- char path[7] = "F1.txt";
- input(groups, path, F1, 0);
- strcpy(path, "F2.txt");
- input(groups, path, F1, 5);
- strcpy(path, "F3.txt");
- input(groups, path, F1, 10);
- output(groups, "Virgin array:");
- printf("--------------------------------\n");
- int i, j;
- char cur[7];
- for(i=0;i<14;i++) {
- for (j = i + 1; j < 15; j++) {
- if (strcmp(groups[i], groups[j]) > 0) {
- strcpy(cur, groups[i]);
- strcpy(groups[i], groups[j]);
- strcpy(groups[j], cur);
- }
- }
- }
- //sortArrayBubble(groups);
- output(groups, "Sorted array:");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement