Question
Please help with this C programming assignment! Your computer program should read 20 student names and grades from an input file, which should be named
Please help with this C programming assignment!
Your computer program should read 20 student names and grades from an input file, which should be named grades.txt. The names should be stored in an array of names which will be a 2D array (an array of 20 names, each of which is an array of 20 character arrays). There are 10 grades per student. The grades should be stored in a 2D array (an array of 20 sets of 10 grades). After the data has been read and stored in the arrays, the program must calculate the average of the grades for each student. Once the averages have been computed, the program must print the names of each student with their average to an output file, which should be named averages.txt. The student name and their average should be on the same line beyond that, you may format the output file however you want. The input file will be formatted with the Student name on a separate line and that students grades on the line under their name.
For example:
Harry Potter 100 83 95 72 95 87 90 100 98 89
Ron Weasley 85 95 100 80 90 75 97 86 79 99
...
Program Requirements: Your program must do the following
Read student names and grades from a file named grades.txt.
Calculate the average of each students grades.
Print the student name and average to an output file named averages.txt.
Your output should be clearly labeled and neatly formatted.
this is what I have so far. I could read the file but I don't know how to calculate the average and how to display it on an output file
#include
int main(void)
{
FILE *studentDataFile;
int i, j = 0;
char names [20][40];
int grades [20][10];
studentDataFile = fopen("grades.txt", "r");
if (studentDataFile == NULL)
printf("File does not exist");
else {
while (!feof(studentDataFile))
{
fscanf(studentDataFile, "%s", names);
fscanf(studentDataFile, "%d", grades);
printf("%s",names);
printf("%d", grades);
}
fclose(studentDataFile);
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started