Exercise #7
Suppose we wanted to write a C++ program that compared the contents of two files and reported on the places where they were different. The two files are expected to contain only ASCII characters and thus, can be compared character by character. For comparison purposes, spaces, tabs, and newline characters are considered the same (white space); characters that differ only in case, as 'h' and 'H' are considered different; punctuation that is different, as a ';' here and a '.' there are considered different. Below are two sample file contents with an example of the type of report we are looking for.
| File A This is the text at the beginning of the file. Here, on the first few lines everything is the same. But, soon a difference is noted. Then, there may be several words that are different; but then again later, the text resumes just as it is in the other file. | File B This is the text at the beginning of the file. Here, on the first few lines everything is the same, almost. But, soon a difference is noted. Then, there could appear various symbols that are different; but then again later, the text resumes just as it is in the other file. |
Difference #1:
File A: same. But, soon
File B: same, almost. But, soon
Difference #2:
File A: there may be several words that
File B: there could appear various
symbols that are different; but then
The program should report differences by showing the text surrounding the difference and highlighting the difference in some way. Since C++ cannot easily show bold, a leading and trailing * might be used. Discuss what it would take to make this program work.