I'm a new programmer, I just was curious and wanted to write some code that would compare two .txt files char by char and check if they are identicle.
this is the code that I wrote, Can someone help me figure out why it doesn't work?
The compiler i'm using is microsoft visual C++ ver.6.0
my compiler shows 0 errors 0 warnings, but the .exe crashes
Code:
// alfred J. Denigris
// write a program that tests if two text files are identicle.
// 1_27_2009
#include <iostream>
#include <fstream>
using namespace std;
ifstream getA;
ifstream getB;
bool test(char a, char b);
int main()
{
int num=0;
char chA, chB;
ifstream getA;
ifstream getB;
getA.open("fileA.txt");
getB.open("fileB.txt");
while (!getA.eof() || !getB.eof())
{
getA.get(chA);
getB.get(chB);
if (test(chA, chB) == true)
cout <<" char number "<<num<<" is "<< chA << "for file a and "<< chB << " For file b. TRUE" <<endl;
else
cout <<" char number "<<num<<" is "<< chA << "for file a and "<< chB << " For file b. FALSE" <<endl;
num++;
}
getA.close();
getB.close();
cout << "end";
return 0;
}
bool test(char a, char b)
{ if(a==b)
return true;
else
return false; }