#include #include #define MAX 28 int compare (struct student * a, struct student * b); /* Student Structure */ struct student { int id; float mt; float final; } Student[MAX]; int main(void) { /* Declare Variables */ FILE * record; FILE * backup; char input[MAX]; static int i = 0; int j; /* Open file for reading */ if ((record = fopen("/home/nate/code/jawn/record", "r")) == NULL) { printf("Error opening record file"); exit(-1); } /* Get lines and parse them */ while ( fgets( &input, MAX, record) != NULL) { sscanf(&input, "%d %.1f %.1f", &Student[i].id, &Student[i].mt, &Student[i].final); i++; } /* Sort the structure */ qsort(&Student, MAX, sizeof(struct student), compare); //test output for (j = 0; j < i; j++) printf("%d %.1f %.f1\n", Student[j].id, Student[j].mt, Student[j].final); return 0; } int compare (struct student * a, struct student * b) { if ( a->id < b->id) return -1; else if (a->id > b->id) return 1; else return 0; }