Question
Using the gets() and fputs() functions, write a C program that accepts lines of text from the keyboard and writes each line to a file
Using the gets() and fputs() functions, write a C program that accepts lines of text from the keyboard and writes each line to a file named text.dat until an empty line is entered. An empty line is a line with no text and just a new line caused by pressing the Enter key.
Hint: (i) When you read strings with gets(), you can use strcmp(string, ) == 0 to judge whether a string is just an empty line. (ii) The string you get from gets() already have a at the end of the string. Therefore, when you print the string to the file, you do not need to add a after it. (iii) Remember to close the file at the end of the program. (iv) You can assume that the maximal length of a string is 1024.
The following is the sample run of the program (The blue font is input by the user).
Please upload your source code file as the attachment and provide three groups of sample runs. For each sample run, you should also provide the screenshot of the contents in text.dat file.
Please enter the text (finish the input with an empty line): This is the first line. Next line is here. Finish the input by a enter keyStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started