我将如何使用 xor 按位运算在 c 中执行逐字节比较?比较两个文件时
#include<stdio.h>
int main()
{
FILE *fp1, *fp2;
int ch1, ch2;
char fname1[40], fname2[40] ;
printf("Enter name of first file :") ;
gets(fname1);
printf("Enter name of second file:");
gets(fname2);
fp1 = fopen( fname1, "r" );
fp2 = fopen( fname2, "r" ) ;
if ( fp1 == NULL )
{
printf("Cannot open %s for reading ", fname1 );
exit(1);
}
else if (fp2 == NULL)
{
printf("Cannot open %s for reading ", fname2 );
exit(1);
}
else
{
ch1 = getc( fp1 ) ;
ch2 = getc( fp2 ) ;
while( (ch1!=EOF) && (ch2!=EOF) && (ch1 == ch2))
{
ch1 = getc(fp1);
ch2 = getc(fp2) ;
}
if (ch1 == ch2)
printf("Files are identical n");
else if (ch1 != ch2)
printf("Files are Not identical n");
fclose ( fp1 );
fclose ( fp2 );
}
return(0);
}
我收到以下警告,然后当我运行它时说我的 test2.txt 为空,但里面有数据?
hb@hb:~/Desktop$ gcc -o check check.c
check.c: In function ‘main’:
check.c:21:8: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
check.c:26:8: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
hb@hb:~/Desktop$
hb@hb:~/Desktop$ ./check
Enter name of first file :test1.txt
Enter name of second file:test2.txt
Cannot open test2.txt for reading hb@hb:~/Desktop$
有任何想法吗?