Write a program to compare two files. Your program must compare two files A and B in a line by line or a byte-by-byte manner according to the first command line option. A ‘-byte’ option tells your program to compare two file byte by byte in binary mode, and a ‘-line’ option tells your program to compare two file line by line in text mode. The names of A and B are given as the second and the third command line option.
The constraints on the parameters are as follow.
The length of a line in text mode is no more than 256
Note that C has short circuit evaluation. That is, if there is an expression A && B, and we evaluate A to be true, we will then evaluate B. However, if we evaluate A to be false, we will NOT evaluate B since the answer is definitively false. The implication is that if you use A && B as a condition to for continuing the reading process of reading two files, you must realize that if A fails B will not be executed.
Input
All input are given as command line options.
Output
We need to output where these two files are different.
If the comparison is byte by byte, the output will be a sequence of lines, each has the format “Bytes %d differ”, where %d is the offset of the byte in the file, starting from 0. If the files are of different length, then we need to output "File %s has %d bytes remaining", where %s is the name of the longer file and %d is the number of bytes that were not compared.
If the comparison is line by line, the output will be a sequence of lines, each has the format "Lines %d differ", where %d is the sequence number the line in the file, starting from 0. If the files have different number of lines, then we need to output "File %s has %d lines remaining", where %s is the name of the longer file and %d is the number of lines that were not compared.
Task Description
Write a program to compare two files. Your program must compare two files A and B in a line by line or a byte-by-byte manner according to the first command line option. A ‘-byte’ option tells your program to compare two file byte by byte in binary mode, and a ‘-line’ option tells your program to compare two file line by line in text mode. The names of A and B are given as the second and the third command line option.
The constraints on the parameters are as follow.
Note that C has short circuit evaluation. That is, if there is an expression A && B, and we evaluate A to be true, we will then evaluate B. However, if we evaluate A to be false, we will NOT evaluate B since the answer is definitively false. The implication is that if you use A && B as a condition to for continuing the reading process of reading two files, you must realize that if A fails B will not be executed.
Input
All input are given as command line options.
Output
We need to output where these two files are different.
Sample Execution
a.exe -line file1 file2
Sample output
Lines 1 differ File file2 has 1 lines remaining
Test Data
You can download the test data (which JudgeGirl uses) from here.