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

#include <stdio.h> main() { FILE *infile, *outfile; char inbuffer[80], m; int nu

ID: 3631669 • Letter: #

Question

#include <stdio.h>
main()
{
FILE *infile, *outfile;
char inbuffer[80], m;
int number, sum = 0;
if ( (infile = fopen("numbers.txt","r") ) == NULL) {
printf("Input file could not be opened ");
exit(1);
}
if ( (outfile = fopen("count.txt","a") ) == NULL) {
printf("Can't open outfile ");
exit(1);
}
while ( (fgets(inbuffer, 80, infile) ) != NULL ) {
sscanf(inbuffer, "%d", &number);
sum = sum + number;
}
fprintf(outfile, "The sum is %d ", sum);
if (fclose(infile) == EOF)
printf("Input file could not be closed ");
return 0;
}


modify the program above that used group-written modules to calculate the average of three values to read integers from a file instead of using input from the keyboard. The number of integers read is determined by the number of integers in the file.
You can use it to have it work using just three values and then implement a counter to count the number of integers input to calculate the average

Explanation / Answer

Dear Friend here is the program modified the way u want PLEASE RATE #include int main() { FILE *infile, *outfile; int feof(FILE *infile); int number, sum = 0; float count=0; if ( (infile = fopen("numbers.txt","r") ) == NULL) { printf("Input file could not be opened "); exit(1); } if ( (outfile = fopen("count.txt","a") ) == NULL) { printf("Can't open outfile "); exit(1); } while ( !feof(infile) ) { fscanf(infile,"%d", &number); sum = sum + number; count++; } fprintf(outfile, "The sum is %d ", sum); fprintf(outfile, "The average is %f ", (sum/count)); if (fclose(infile) == EOF) printf("Input file could not be closed "); return 0; }