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

write a program that prompts the user for a filename, opens thefile, and prints

ID: 3615393 • Letter: W

Question

write a program that prompts the user for a filename, opens thefile, and prints its contents to the screen one word perline.

You must use a function called filePrint to do the actualprinting. The function should not return anything. Itsonly parameter should be the name of the file to read andprint. The function should open the file, read words one at atime, and print them to the screen. You do not need tostore the words. Simply read each word and print it oneat a time until you reach the end of the file. The functionshould not do any additional I/O. The prompting of the filename should be done in main.

A sample run of the program is below. User input is in boldfor clarity.

Enter a file to print: test.txt

hi
there
i
am
a
file
to
test
lab8

Explanation / Answer

please rate - thanks #include #include #include void printwords(const char *); main() { FILE *fp; char filename[20]; printf("Enter a file to print: "); scanf("%s",&filename); printwords(filename); getch(); } void printwords(const char *filename) {    FILE *fp;    int n = 0;    char word[20];    if((fp = fopen(filename, "r")) != NULL)       {while( fscanf(fp,"%s",word)!=EOF)         printf("%s ",word);        } fclose(fp); }