发布网友 发布时间:2022-04-20 11:47
共1个回答
热心网友 时间:2023-09-12 20:54
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string.h>
#define READ_BUFFER_SZ (1*1024)
int main(int argc, char* argv[])
{
FILE *file1 = fopen(argv[1], "rb");
FILE *file2 = fopen(argv[2], "rb");
unsigned char buf1[READ_BUFFER_SZ];
unsigned char buf2[READ_BUFFER_SZ];
int readbyte1 = 0;
int readbyte2 = 0;
int diff = 0;
while (1) {
readbyte1 = fread(buf1, sizeof(char), READ_BUFFER_SZ, file1);
readbyte2 = fread(buf2, sizeof(char), READ_BUFFER_SZ, file2);
if (readbyte1 > 0 && readbyte2 >0) {
if (memcmp(buf1, buf2, READ_BUFFER_SZ)) {
diff = 1;
break;
} else {
continue;
}
} else if (readbyte1 == 0 && readbyte2 == 0) {
break;
} else {
diff = 1;
break;
}
}
fclose(file1);
fclose(file2);
if (diff) {
printf("%s and %s is diff\n", argv[1], argv[2]);
} else {
printf("%s and %s is same\n", argv[1], argv[2]);
}
return 0;
}