Yeh well this is my sucky file comparator. I've been working on. It should have taken me all of 10 minutes to make, but instead it took me all of ten days o_O. I got a little confused between C++ char* and strings in Java, but now I understand it thanks to BA and the program seems to work okay. As far as I am aware it can only compare non-executable files. I might work on it again someday, but I have spent all the time on it I think I should have. Since the project is rather pointless and I have already gained the concept I'm going to move on. Here is the source:
[php]
/* File Comparator
Created by: Shaun Carter (why06)
Date: 10/03/2009*/
#include <iostream>
#include <fstream>
using namespace std;
int CompareFiles(fstream &file1, fstream &file2);
int main()
{
char file1[50];
char file2[50];
bool filesCompared = false;
while(!filesCompared)
{
// Starting message
cout << "Enter: File1\n";
cin >> file1;
cout << "Enter: File2\n";
cin >> file2;
//Declarinng fstream variables that I will use for the binary comparison//
cout << "Opening: " << file1 <<endl;
fstream f1((const char*)file1, ios::binary | ios::in | ios:

ut);
if(!f1){
cout << "Cannot open " <<file1 << endl;
system("pause");
return 1;
}
cout << "Opening: " << file2 << endl;
fstream f2((const char*)file2, ios::binary | ios::in | ios:

ut);
if(!f2){
cout << "Cannot open " << file2 << endl;
system("pause");
return 1;
}
/////////////////////////////////////////////////////////////////////////////
//Execution passes to CompareFiles. Will return 0 (are equal), 1 (file1 is larger), 2 (file2 is larger)
cout << "Comparing...\n";
int result = CompareFiles(f1, f2);
// Finally returns result of Comparison.
if(result)
{
cout << "Files are not the same." << "\n";
if(result == 1)cout << file1 <<" is larger then " << file2 << ".\n";
else if( result == 3) cout << "binary conctructions are not the same.\n";
else cout << file2 <<" is larger then " << file1 << endl;
}
else cout << "These files are the same.\n";
filesCompared = true;
}
system("pause");
return 0;
}
int CompareFiles(fstream &file1, fstream &file2)
{
char buf1[50];
char buf2[50];
file1.read( (char*) buf1, sizeof buf1);
file2.read( (char*) buf2, sizeof buf2);
if(file1.gcount() != file2.gcount())
{
cout << "Differing sizes...\n";
if(file1.gcount() > file2.gcount()){ file1.close(); file2.close(); return 1;}
else return 2;
}
else
{
cout << "Same size. \nRunning binary comparison...\n";
// Binary comparison
char f1,f2;
while(file1.get(f1))
{
file2.get(f2);
if(f1 != f2 ) {cout << "These files are not the same.\n"; return 3;}
}
cout << "Finished Binary Comparison.\n";
file1.close();
file2.close();
return 0;
}
}
[/php]
I took zeco's idea and used the php tags to make it colored.