1.如果系统有diff 命令的话可以直接用diff 命令 : diff src.txt dest.txt
2.C语语言调用diff 命令:
rjl@rjl-desktop:~/test$ vim test.c
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
int main()
{
char cmd[1024]={0};
struct stat st;
memset(cmd,0,sizeof(cmd));
sprintf(cmd,"diff 1.txt 2.txt >>e.txt");
system(cmd);
if(access("e.txt",F_OK)!=0)
printf("------------------------------file isnot existence!\n\r");
else
{
int fd = open("e.txt",O_RDWR);
fstat(fd,&st);
if(st.st_size)
printf("------------------------------two file are diffenert!\n\r");
else
printf(".................................two file same OK!\n\r");
}
return 0;
}