Chapter 13: Programming ExercisesΒΆ

1. Write a C++ program that compares two text files and
   prints the lines where they first differ.  The program
   reads one line each from two files until a differing
   line is found or one of the files is exhausted, in
   which case the line read from the other file is the
   first differing line.  If both files are exhausted
   simultaneously and no differing line has been found,
   the two files are identical.

   The program must take into account that two files may
   be the same in the text, but only the number of spaces
   or blanks on a line are different.  Therefore, each
   line must be squeezed to eliminate blanks or spaces
   before they are compared.  This method will give a true
   comparison of two files.

Previous topic

Chapter 13 File Processing

Next topic

Chapter 13: Programming Projects

This Page