/* bmatch.c Binary Match check program */
#include <stdio.h>
void usage(char *prog)
{
fprintf(stderr, "Usage : %s file1 file2\n", prog);
fprintf(stderr, "Function : Binary Match check program\n");
exit(0);
}
main(int argc, char *argv[])
{
FILE *fp1, *fp2;
char *p1, *p2;
char buf1[1024], buf2[1024];
int c1, c2, contflag;
long count = 0;
if(argc < 3) usage(argv[0]);
fp1 = fopen(argv[1], "rb");
if(fp1 == NULL)
{
fprintf(stderr, "Error : file(%s) can't open.\n", argv[1]);
exit(-1);
}
fp2 = fopen(argv[2], "rb");
if(fp1 == NULL)
{
fprintf(stderr, "Error : file(%s) can't open.\n", argv[1]);
exit(-1);
}
do
{
c1 = fread(buf1, sizeof(char), 1024, fp1);
c2 = fread(buf2, sizeof(char), 1024, fp2);
contflag = (c1 == 1024) && (c2 == 1024);
p1 = buf1;
p2 = buf2;
while(c1--)
{
if(c2-- == 0) break;
count++;
if(*p1++ != *p2++)
{
fprintf(stderr, "file1(%s) & file2(%s) not matched at %ld byte.\n",
argv[1], argv[2], ++count);
exit(0);
}
}
} while(contflag);
fprintf(stderr, "file1(%s) & file2(%s) matched in %ld byte.\n",
argv[1], argv[2], count);
return 0;
}
|