Project Description
Start with the following code:
1 |
|
Create a C++ application that converts an old-style text file into a format more appropriate for use in a computer, smart-phone, or e-book reader. Specially, this program converts an UTF-8 text file (for example, PlatoTest.txt) to an xhtml 1.0 file (for example, PlatoTest.html) containing the same textual content as the original UTF-8 text file.
Note: If the input file has three newlines in a row, the output file should have only two
tags replacing the three newlines. Overall, the number of break tags is always one less than the number of consecutiveor singlenewlines.
The executable file must be named: txt2html.exe
The program will operate as a command-line utility (not a console input program).
An Example - Convert PlatoTest.txt to PlatoTest.html
Below is an UTF-8 text file named “PlatoTest.txt”. Note that represents an 1
2
3
4
5The Republic, by Plato
The Project Gutenberg EBook of The Republic, by Plato
This eBook is for the use of anyone anywhere at no cost and with almost no restrictions whatsoever. You may copy it, give it away or re-use it under the terms of the Project Gutenberg License included with this eBook or online at www.gutenberg.org
Title: The Republic
Author: Plato
The UTF-8 text file should convert to the html file named “PlatoTest.html” with the following source code:
1 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
This example would be run from the command prompt by typing:1
txt2html.exe PlatoTest.txt
or1
txt2html.exe PlatoTest.txt PlatoTest.html
Switch
If the user provides an optional command line parameter “-r”, print the report (described in the next section) to the console:1
txt2html.exe -r PlatoTest.txt
or1
txt2html.exe PlatoTest.txt PlatoTest.html -r
or1
txt2html.exe PlatoTest.txt -r PlatoTest.html
Report
Provided the “-r” switch your program will display to the console a report that displays:
- The number of complete lines read from the input file.
- The number of paragraphs (indicated by
tags)
Additional Examples
1 | txt2html.exe -r "War and Peace.txt" |
or1
txt2html.exe "War and Peace.txt" -r
or1
txt2html.exe "War and Peace.txt" W&P.html -r
or1
txt2html.exe War&Peace.txt -r War&Peace.html