I am trying to read from a file and save the data into an array of struct. However I am at loss on how do I go about it.
The struct is like this
struct Student students {
int stuid;
char name[21];
double grade;
}
The text file is something like this
1,76.50,Joe Smith
2,66.77,John Campbell
3,88.99,Jane Common
The code I tried ended up something like this
//declaring the struct
struct Student test[3];
int loadgrade(struct Student* student, FILE* file) {
while (fscanf(file, "%d,%lf,%21[^\n]", &student.stuid, &student.grade, &student.name) == 3)
I am not sure how I would save the data into the array, as the way I have it will only save to the first element and never go on. Do I loop inside the while statement of reading the file? Do I make another struct or temp variable to read the file and then loop it to transfer it? I am at a loss on this and would appreciate any kind of enlightenment.