I seem to have tried everything I know. This thing is due in a few days so any help would be greatly appreciated. I read numbers from a text file and sort them.
here is the contents of the grades_data.txt fileCode:#include <stdio.h> #include <stdlib.h> #define MAXLINE 30 void sort(int[], int); void display(int[], int); FILE *fp; int main(void) { int x; int i; fp = fopen("C:\\grades_data.txt", "r"); char line[MAXLINE]; while(fgets(line, MAXLINE, fp) != NULL && line[0] != '\n') fputs(line, stdout); for(i = 0; i < MAXLINE; i++) x = atoi(line); sort(x, 30); fclose(fp); system("PAUSE"); return 0; } void sort(int n[], int size) { for(int i = 0; i < size; i++) { for(int j = 0; j < size; j++) { if(n[i] < n[j]) { int temp = n[i]; n[i] = n[j]; n[j] = temp; } } } display(n, size); } void display(int n[], int size) { int i; for(i = 0; i < size; i++) { printf("This is the sorted list %d :\n", n[i]); } }
Code:9 25 55 1 4 98 74 44 11 19 0 85 64 23 3 6 99 51 100 0 68 97 90 13 17 45 38 42 12 24



LinkBack URL
About LinkBacks


