I wrote a program to compare two text files character by character and its not working probably an easy thing im just not seeing.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char *argv[]){
string s1;
string s2;
char c1, c2;
if(argc !=3) { // check command line
cerr << "Usage: " << argv[0] << " file1 file2" << endl;
return 1;
}
ifstream ifs1( argv[1] ); // get file1
if( !ifs1 ){
cerr << "can't open " << argv[1] << endl;
return 1;
}
ifstream ifs2( argv[2] ); // get file2
if( !ifs2 ){
cerr << "can't open " << argv[2] << endl;
return 1;
}
for( int i = 0; !ifs2.eof(); i++ ){
getline( ifs2, s2 );
if( !ifs1.eof() ){
getline( ifs1, s1 );
c1 = s1[i];
c2 = s2[i];
if( c1 != c2 )
cout << endl << "Files differ at line" << (i + 1) << endl;
}
}
return(0);
}