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
|
#include <stdio.h>
#include <cstdlib>
#include <sstream>
using namespace std;
int main ()
{
int i =0;
char c1 =0;
char c2 =0;
char preveusc1 =0;
char preveusc2 =0;
int wrong =0;
long rFile1Size;
long rFile2Size;
FILE * pFile;
FILE * rFile1;
FILE * rFile2;
rFile1 = fopen ("myfile.bin","rb");
rFile2 = fopen ("myfile2.bin","rb");
if (rFile1!=NULL && rFile2!=NULL){
// get size
fseek (rFile1 , 0 , SEEK_END);
rFile1Size = ftell (rFile1);
rewind (rFile1);
fseek (rFile2 , 0 , SEEK_END);
rFile2Size = ftell (rFile2);
rewind (rFile2);
// compare
while(i<rFile1Size){
fseek ( rFile1 , i , SEEK_SET );
fseek ( rFile2 , i , SEEK_SET );
c1 = fgetc (rFile1);
c2 = fgetc (rFile2);
if (wrong>0){
fseek ( rFile1 , (i-1) , SEEK_SET );
preveusc1 = fgetc(rFile1);
fseek ( rFile1 , (i+1) , SEEK_SET );
fseek ( rFile2 , (i-1) , SEEK_SET );
preveusc2 = fgetc(rFile2);
fseek ( rFile2 , (i+1) , SEEK_SET );
}
if (c1!=c2){
stringstream convert;
stringstream convert2;
convert2 << c2;
if (wrong>0 && preveusc1!=preveusc2){convert << (i-1);}else{convert << i;}
pFile = fopen (convert.str().c_str(),"ab");
if (pFile!=NULL){
fputs (convert2.str().c_str(),pFile);
fclose (pFile);
}
wrong++;i++;}else{i++;}
}
//printf("%d",wrong);
fclose (rFile1);
fclose (rFile2);
}
system("PAUSE");
return 0;
}
|