Reading from file into array of structures.
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:
Smart, Maxwell:868686:55:64:99:99:C+
This is the code I'm trying to use:
Code:
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)
{
i++;
}
}
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?