I'm trying to read a student record into an array (sAry) of STUDENT structures, from a text file.
The students name is a string, max 20 characters.
Student ID is a six digit integer.
Four, three digit, integer score fields.
A grade which is a string, max 2 characters.
All fields are separated by a semicolon, example:
This is the code I'm trying to use:
I'm getting a segmentation fault. I've tried playing around with it and nothing. Can anyone point out the flaw I must be missing?
while (i < MAX_STUDENTS)
fgets(buffer, 500, FILE);
if (sscanf(buffer, "%20[^:]%*[:]%d%*[:]%d%*[:]%d%*[:]%d%*[:]%d%2[^:]",
sAry[i].name, &sAry[i].id, &sAry[i].score1,
&sAry[i].score2, &sAry[i].score3, &sAry[i].score4, sAry[i].grade) > 0)