Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

question 1 Using the gets() and fputs() functions, write a C program that accepts lines of text from the keyboard and writes each line to

question 1

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.

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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions