Im working on a program that opens a file of student records and stores them in an array of structures.
My structure looks like this
Right now im having trouble going through the data in the file and storing it.
The data looks like this
I am using a loop with fgets and sscanf, which will stop at each new line because of fgets and store the string in a buffer then im trying to use sscanf to go through the buffer data and pull out what I need.
I can get through the name and student id(the first two pieces of data separated by : ) but am stuck on how to store the next four scores.
My code for the first part is
It should read up to 20 characters or stop at a colon. Then skip the colon and read 6 more or stop at the next colon. This is where im starting to get lost. I need to find the average of the next four numbers to be part of my structure as well. What is the best way to read in these numbers so I can also find their average? Additionally the scores can have a range from 0 to 150
sscanf(buffer, "%20[^:]%[:]%6[^:]%[:]", stuAry[i].name, stuAry[i].studentID);
I think I can get through the letter grade at the end. I was thinking of something like or even just simply thanks