当前位置: 代码迷 >> C语言 >> 如何比较两个文件内容是否相同
  详细解决方案

如何比较两个文件内容是否相同

热度:139   发布时间:2007-11-20 15:12:40.0
如何比较两个文件内容是否相同
小弟想编程实现比较两个文件的内容是否相同,下面是代码:
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>

int main()
{
int n1,n2,fd1,fd2,cr;
char *buf1[1024], *buf2[1024],*buf3[1024],*buf4[1024];

if((fd1=open("file1.c",O_RDONLY))==-1)
perror("open file1 error");
while((n1=read(fd1,buf1,1024))>0)
{
if(write(buf2,buf1,n1)!=n1)
perror("write error1");
}

if((fd2=open("file2.c",O_RDONLY))==-1)
perror("open file2 error");
while((n2=read(fd2,buf3,1024))>0)
{

if(write(buf4,buf3,n2)!=n2)
perror("write error2");
}

cr=strcmp(buf2,buf4);
if(cr==0)
printf("Two files are the same");
else
printf("Two files are different");

return 0;
}

编译执行后提示:
write error1: Bad file descriptor
write error2: Bad file descriptor

请高手指教下 什么问题啊?
搜索更多相关的解决方案: include  文件  int  sys  

----------------解决方案--------------------------------------------------------

重写吧


----------------解决方案--------------------------------------------------------
fd1=open("file1.c",O_RDONLY))
int
n1,n2,fd1,fd2,cr;

不知道文件指针.FILE*.
----------------解决方案--------------------------------------------------------
?
----------------解决方案--------------------------------------------------------
  相关解决方案