1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
#include <string>
using namespace std;
int main()
{
string file1, file2;
ifstream Textfile1, Textfile2;
file1="text1(3).txt" ;
file2="banned(1).txt" ;
Textfile1.open( file1.c_str(), ios::binary );
Textfile2.open( file2.c_str(), ios::binary );
if (!Textfile1)
{cout << "Couldn't open the file " << file1<<endl;
return 1;
}
if (!Textfile2)
{cout << "Couldn't open the file " << file2 << endl;
return 1;
}
int i1,i2;
i1 = 0;
i2 = 0;
string str;
while(!Textfile1.eof())
{
getline(Textfile1,str);
i1++;
}
//Textfile1.clear(); // set new value for error control state //
//Textfile2.seekg(0,ios::beg);
while(!Textfile2.eof())
{
getline(Textfile2,str);
i2++;
}
Textfile1.clear();
Textfile1.seekg(0,ios::beg);
Textfile2.clear();
Textfile2.seekg(0,ios::beg);
if(i1 != i2)
{
cout << "Different number of lines in files!" << "\n";
cout << file1 << " has " << i1 << " lines and "<< file2 <<" has" << i2 << " lines" << "\n";
return 1;
}
char string1[256], string2[256];
int j = 0, error_count =0;
while(!Textfile1.eof())
{
Textfile1.getline(string1,256);
Textfile2.getline(string2,256);
j++;
if(strcmp(string1,string2) != 0)
{
cout << j << "-the strings are not equal " << endl;
cout << " file1 " << string1 << endl;
cout << " file2: " << string2 << endl;
error_count++;
}
}
if (error_count > 0) {
cout << "files are diffrent"<< endl;}
else {cout << "files are the same"<< endl;}
return 0;
system( "pause" );
}
|