Hi, I'm a beginner at programming and would appreciate some help with this.
I need to open a text file and then organize it alphabetically. So far I can open the file, and I know how to do a simple bubble sort, I'm just not sure how to pit the two of them together. Opening the file:
And a the bubble sort would be something like:Code:#include <stdio.h> void main () { char file_name[30]; FILE *file_ptr; printf("Enter the name of the file to open >"); scanf("%s",file_name); file_ptr = fopen(file_name, "r"); if (file_ptr != NULL) printf("File open OK\n"); else printf("Error opening file %s\n", file_name); }
I just dont know how to go about implementing the bubble sort function once the file is open. I'm guessing it has to do with reading the data into an array but I dont know where to go from here. Any help would be greatly appreciated.Code:void bubble_sort() { int temp; for (int i = 0; i < size - 1; i++) for (int j = 0; j < size - 1; j++) { if (A[j] > A[j+1]) { temp = A[j]; A[j] = A[j+1]; A[j+1] = temp; } } }



LinkBack URL
About LinkBacks


