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 to enter a filename (assume no more than 2

ID: 3626193 • Letter: W

Question

Write a program that prompts the user to enter a filename (assume no more than 24 characters). Use the scanf function to read the file name. Then prompt the user to enter a sentence from the keyboard and write that sentence to the file whose name was entered. (Note: the sentence may include spaces, so be sure to use an input function that can handle that case, but will not be longer than 80 characters.) Look at the output file to verify that it was written correctly.

I will appreciate answer to question in C Programming. Thank you.

Explanation / Answer

Dear user, Here is the code below:
#include<stdio.h>
void main( )
{
   FILE *fp;
   char fname[24],ch;
   clrscr();
printf("Enter the file name");
   scanf("%s",fname);
   fp=fopen(fname,"w");
if(fp==NULL)
{
printf(" unable to create a file");
   exit(0);
}
while(ch==getchar( )!=EOF)
{
     fputc(ch,fp);
}
fclose(fp);
}
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