最近研究dxf文件格式,被dxf文件长长的文件搞得比较晕,想知道每种图元在文件中的表示方式,采用空表建立图元,然后寻找在文件中的位置,linux下有cmp比较文件命令,我想在windows下也可以实现一个无参数的简易版,这样可以加快查找速度。
程序清单如下:
/* This is a porgram to compare the differents between two files.
* input: file pointer
* ouput: if same return noting ,else return the line of diff first come
* version :test
* author:song
*/
#define STRLEN 30 //字符最大长度
#include
#include
int cmp(const char* fl1,const char* fl2)
{
int linecount=0;
char codevalue[STRLEN];
char codevalue2[STRLEN];
FILE *fp1,*fp2;
if((fp1=fopen(fl1,"r"))==0)
{
perror("error in open file1");
return -1;
}
if((fp2=fopen(fl2,"r"))==0)
{
perror("error in open file2");
return -1;
}
while(!feof(fp1)&&!feof(fp2))
{
linecount++; //记录行数
fscanf(fp1,"%s",codevalue);
fscanf(fp2,"%s",codevalue2);
if(strcmp(codevalue,codevalue2)!=0)
return linecount; //返回
}
return 0;
}
//下面是一个测试
int main()
{
int n=0;
char *f1="d:\\1.txt";
char *f2="d:\\2.txt";
if(n=cmp(f1,f2))
printf("first diff in line %d\n",n);
else
printf("same files\n");
return 0;
}
阅读(945) | 评论(0) | 转发(0) |