Question
The C program below was written to read a file called scores.dat and then output another file called scores.out. The file scores.dat contains 4 columns
The C program below was written to read a file called scores.dat and then output another file called scores.out. The file scores.dat contains 4 columns of just integers, the first for student ID, the second, third and fourth columns are for student grades on tests. The program below just outputs the data with column titles. Please help me to modify this program in such a way that it will read the data from scores.dat file and calculate each students lowest score, highest score and average score. Then it must write students id number, students lowest score, highest score and average score to the output file scores.out. The scores.out file must have an appropriate title for each column.
#include
int main(void)
{
FILE *fPtr;
FILE *fPtrOut;
if ((fPtrOut = fopen("scores.out", "w")) == NULL) {
puts("cant open file to write");
}
if ((fPtr = fopen("scores.dat", "r")) == NULL) {
puts("cant open file to read");
}
else
{
int id;
int score1;
int score2;
int score3;
printf("ID SCORE1 SCORE2 SCORE3 ");
fprintf(fPtrOut, "ID SCORE1 SCORE2 SCORE3 ");
fscanf(fPtr, "%d%d%d%d", &id, &score1, &score2, &score3);
while (!feof(fPtr)) {
printf("%d %d %d %d ", id, score1, score2, score3);
fprintf(fPtrOut, "%d %d %d %d ", id, score1, score2, score3);
fscanf(fPtr, "%d%d%d%d", &id, &score1, &score2, &score3);
}
fclose(fPtr);
fclose(fPtrOut);
}
}
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