Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program to read a set of scores from a text file, count the number of

ID: 3864102 • Letter: W

Question

Write a C program to read a set of scores from a text file, count the number of scores over 80, copy the scores over 80 into a new file, save it as ’OUTPUTFILE.DAT’, and finally, print the list of number of scores over 80 on screen. Test your program with an input file (name it as ’INPUTFILE.DAT’) containing the following values:

100
50
20
82
60
30
88
78
90
100
63
55
30
85
93
96
63

A sample program execution and output is depicted in below figure:

Start of Program Printing scores over 80 on screen **E*a 100 82 88 90 100 85 93 96 There were 8 scores over 80 End of Program

Explanation / Answer

Please find the C program to find the number greater than 80 in the file named INPUTFILE.DAT :

#include <stdio.h>
int main(void) {
FILE *in, *out;
int x;

if ((in = fopen("INPUTFILE.DAT", "r")) == NULL) {
fprintf(stderr, "Could not open INPUTFILE.DAT for reading. ");
return 1;
}

if ((out = fopen("OUTPUTFILE.DAT", "w")) == NULL) {
fprintf(stderr, "Could not open OUTPUTFILE.DAT for writing. ");
fclose(in);
return 2;
}

while (!feof(in)) {
fscanf(in, "%d", &x); /* read a number */
if (!feof(in) && x > 80) /* Compare all the numbers , Find for the numbers above 80 */
fprintf(out, "%d ", x);
}

fclose(in);
fclose(out);

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote