编写比较两个文件是否相同的程序,若相同,输出“Compare OK!”;否则,输出“Not Equal”.

来源:百度知道 编辑:UC知道 时间:2024/07/05 06:01:47
程序不需要太长 越简单越好~

#include <stdio.h>

int main()
{
const char* file1 = "test1.txt";
const char* file2 = "test2.txt";
FILE* fin1 = fopen(file1, "r");
FILE* fin2 = fopen(file2, "r");

while (!feof(fin1) && !feof(fin2)) {
if (fgetc(fin1) != fgetc(fin2))
break;
}
if (feof(fin1) && feof(fin2))
printf("Compare OK!\n");
else
printf("Not Equal\n");

fclose(fin1);
fclose(fin2);
}

#include<stadio.h>
void main()
{
int a,b,i,*p1,*p2,x=0;
char a[]="你要比较的文字或字符串1";
char b[]="你要比较的文字或字符串2";
p1=a;
p2=b;
for(;p1!='\0',p2!='\0';p1++,p2++)
if(p1!=p2) x+=1;
if(x!=0) pringf(“Not Equal”);
if(x=0) pringf(“Compare OK!”);
}

采用C语言编写的,希望对你有用,还有你要注意字符格式,尽量不要复制,保证是英文小写

good luck!

#i