Hello,
I've a file which contains names and grades of students, and I'd like to write a program which can sort their grades (like midterm 1,midterm 2) according to user choice. I wrote as far as the choice part and opening the file, yet I don't know how to make program read only certain part of the file (like only Midterm 1 grades for example) and sort them only,then need to define a structure named “student”(so I can store name,surname and scores of each student under the same variable name)At the end, all data in the file needs to be stored in an array of new data type named “student”. Here's what I've wrote so far;
#include <stdio.h>
#include <stdlib.h>
int main()
{
int choice,studentnumber,midterm1,midterm2,midterm3;
char name[30];
char surname[30];
FILE *cfPtr;
if ((cfPtr = fopen("grades.txt", "r")) == NULL)
printf("Dosya açılamadı.\n");
else {
printf("%s%s%s%s\n", "StudentNumber", "Name", "Surname", "Midterm1", "Midterm2", "Midterm3");
fscanf(cfPtr, "%d%s%s%d%d%d", &studentnumber, &name, &surname, &midterm1, &midterm2, &midterm3);
while (!feof(cfPtr)) {
printf("%4d%15s%15s%10d%10d%10d\n", studentnumber, name,surname, midterm1, midterm2, midterm3);
fscanf(cfPtr, "%d%s%s%d%d%d", &studentnumber, &name, &surname, &midterm1, &midterm2, &midterm3);
}
printf("What would you like to do? \n"
"1- Sort according to midterm 1\n"
"2- Sort according to midterm 2\n"
"3- Sort according to midterm 3\n"
"4- Exit\n"
scanf("%d",&choice);
while (choice != 4);{
fprintf("%4d%15s%15s%10d%10d%10d\n", studentnumber, name,surname, midterm1, midterm2, midterm3);
switch(choice) {
fclose(cfPtr);
}
system("PAUSE");
return 0;
}
After those, I have absolutely no idea what to do. Any ideas to give me? Thanks :)