I am working on the last part of an encryption/decryption program and have to compare the original input file to the final output file character by character to ensure that they are identical. I have tried a few different ways to do this to no avail. When I tried this code:
inputFile.get(inputChar);
outputFile.get(outputChar);
while(inputFile.good() && outputFile.good())
{
if(inputChar != outputChar)
{
cout << "The files are not identical\n\n\n";
return 1;
}
inputFile.get(inputChar);
outputFile.get(inputChar);
}
if(inputFile.eof() && outputFile.eof())
{
cout << "The files are identical.\n\n\n" << endl;
}
else if(inputFile.eof() || outputFile.eof())
{
cout << "One of the files has ended before the other, they are not identical." << endl;
}
It seems to go straight to telling me that one of the files has ended before the other and that they are not identical. I also tried:
while (inputFile.get(inputChar))
{
if (!outputFile.get(outputChar) || (inputChar != outputChar))
{
cout << "The files are not identical" << endl;
}
}
if (!outputFile.get(outputChar))
{
cout << "The files are identical" << endl;
}
else
{
cout << "The files are not equal";
}*/
And this is also telling me that they are not identical when I run the program. The two files are exaclty the same size, there is only one character in each of them (that's what I am testing with at the moment, just the letter a in each file), there is no extra characters or spaces in either of the files, the only difference between the two is the name of the file. Does anyone have any ideas, suggestions, or examples as to how to do this correctly, or why it might be telling me that they are not identical when in actuality it seems that they are to me. I will post the full program code if need be, just ask if you need to see if for anything. Thanks in advance for your help.