Write a function read_records() that read 4 student records from
“roster.txt” and stores them in an array of student_t variables such that the first
array slot stores information of the first student, etc. A0110793H 3 4 A- 4 C 4 B+
Function prototype is as follows.
void read_records(student_t stu[]);
1
Expert's answer
2017-07-27T15:50:06-0400
void read_records(student_t stu[]) { int i, j; FILE* f = fopen("roster.txt", "r"); if (f) { for(i=0; i<4; i++) { /* I guess that number is number of grades */ fscanf(f, "%s %d", stu[i].name, stu[i].grades); for(j=0; j<stu[i].grades; j++) { fscanf(f, "%d %s", stu[i].grade_val[j], stu[i].grade_letter[j]); } } fclose(f); } }
Comments
Leave a comment