Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

To display the final line in a file, you need to find it by going to the end of the file and then backing up

To display the final line in a file, you need to find it by going to the end of the file and then

backing up a character at a time until it reaches the beginning of the last line. For example,

// Go to the end of the file. infile.seekg(0, ios::end); // Move backwards to beginning of the // final char in the file and read it in infile.seekg(-1, ios::cur); ch = infile.get();

Then use while loop to back up until we find a newline. It is where the last sentence starts.

image text in transcribed
NOTE: Using an editor, you should create a simple text file that can be used to test this program. 3. Punch Line Write a program that reads and prints a joke and its punch line from two different files. The first file contains a joke, but not its punch line. The second file has the punch line as its last line, preceded by "garbage." The main function of your program should open the two files and then call two functions, passing each one the file it needs. The first function should read and display each line in the file it is passed (the joke file). The second function should display only the last line of the file it is passed (the punch line file). It should find this line by seeking to the end of the file and then backing up to the beginning of the last line. Data to test your program can be found in the joke.txt and punchline.txt files. Tail Program Write a program that asks the user for the name of a file. The program should display

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxiv Special Issue On Database And Expert Systems Applications Lncs 9510

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Hendrik Decker ,Lenka Lhotska ,Sebastian Link

1st Edition

366249213X, 978-3662492130

More Books

Students also viewed these Databases questions