View the step-by-step solution to:

How to make a new text file by using any text editor (like Notepad and putting down some numbers in the file like 1 2 3 etc. You can make several...

How to make a new text file by using any text editor (like Notepad and putting down some numbers in the file like 1 2 3 etc.. You can make several lines in typing your numbers.


How to modify the code to calculate the average of the numbers of the read file.


#include <stdio.h>

int main(){

FILE *test; 


int sum=0, value;

test = fopen("C:\numbers1.txt","r");// file path

if(test == NULL)   

printf("Error in opening the numbers.txt n");

else   

printf("numbers.txt has opened successfullyn");


 while(fscanf(test, "%d", &value)!=EOF) {        

sum += value;            


}

printf("nThe sum is: %dn", sum);


fclose(test);     


return 0;

}

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question