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).

Using the gets() and fputs() functions, write a C program that accepts

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 key

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!