Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 5a)
- int readStudents(student_t students[], char *fileName)
- {
- int i, studentIndex = 0;
- FILE * fp;
- fp = fopen(fileName, "r");
- while(fscanf(fp, "%s", students[studentIndex].name) != EOF)
- {
- /* Read numCourses */
- fscanf(fp, "%d", &students[studentIndex].numCourses);
- /* Read all the scores */
- for(i = 0; i < students[studentIndex].numCourses; i++)
- fscanf(fp, "%d", &students[studenIndex].scores[i]);
- /* End of 1 student data reading */
- studentIndex++;
- }
- fclose(fp);
- return studentIndex;
- }
- 5b)
- int findStudentByName(student_t students[], int numberStudents, char name[])
- {
- int i;
- for(i = 0; i < numberStudents; i++)
- if(strcmp(students[i].name, name) == 0)
- return i;
- return -1;
- }
- 5c)
- float averageScore(student_t stu)
- {
- int i;
- float sum = 0;
- for(i = 0; i < stud.numCourses; i++)
- sum += stud.scores[i];
- return sum / stud.numCourses;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement