Answer to Question #69328 in C for LEE JIA WEI

Question #69328
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);
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS