Write a program that prompts the user to enter a filename (assume no more than 2
ID: 3626124 • 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 it if the response is in C Programming.
Thank you for your precious time.
Explanation / Answer
#include #include int main() { char name[24],sen[100]; FILE *file; clrscr(); printf("Enter name of file:"); scanf("%s",&name); fflush(stdin); file = fopen(name,"a+"); /* apend file (add text to a file or create a file if it does not exist.*/ printf("Enter a sentence:"); gets(sen); fflush(stdin); fputs(sen,file); /*writes*/ fclose(file); /*done!*/ getch(); /* pause and wait for key */ return 0; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.