I have a text file that has blocks of student data. E.g.:
student number
name
number of subjects
subject code 1
subject code 2
subject....... etc
student number
name
..
.. etc
My problem arises when I want to read in the subject codes, as each block will have a different amount of subjects I need to just read each one in until there are no more subjects. There is where the empty line will be. Therefore I want to create a loop that will read up until the new line.
Btw, each block get saved into an array of structs.
Have tried using strcmp
but wasn't sure what I was doing, have no idea otherwise.
for(int j = 0; j < 8; j++) {
fscanf(fptr,"%s",gRecs->subject[j].subjectcode);
fscanf(fptr,"%d",&gRecs->subject[j].enrolnmentstat);
fscanf(fptr,"%d",&gRecs->subject[j].mark);
printf("%s\n",gRecs->subject[j].subjectcode);
printf("%d\n",gRecs->subject[j].enrolnmentstat);
printf("%d\n",gRecs->subject[j].mark);
}
I need to add possibly a while loop within the for loop so that it resets when a empty line is encountered.
The for loop is so that each one is saved into a separate array of structs, 8 is the amount given by the assignment.