想找到两个文件中第一个不相同的行,但每次结果都是第一行,求大神解答!!!
voidfilecomp(FILE*fp1,FILE*fp2){charline1[MAXLINE],line2[MAXLINE];char*lp1,*lp2;do{lp...
void filecomp(FILE *fp1,FILE *fp2)
{
char line1[MAXLINE],line2[MAXLINE];
char *lp1,*lp2;
do
{
lp1=fgets(line1,sizeof(line1),fp1);
lp2=fgets(line2,sizeof(line2),fp2);
if(lp1==line1 && lp2==line2)
{
if(strncmp(line1,line2,MAXLINE)!=0)
{
printf("first difference line:\nfile1:%s\nfile2:%s\n",line1,line2);
lp1=lp2=NULL;
}
}
else if(lp1!=line1 && lp2==line2)
{
printf("end of file.");
}
else if(lp1==line1 && lp2!=line2)
{
printf("end of second file2.");
}
}while(lp1==line1 && lp2==line2);
} 展开
{
char line1[MAXLINE],line2[MAXLINE];
char *lp1,*lp2;
do
{
lp1=fgets(line1,sizeof(line1),fp1);
lp2=fgets(line2,sizeof(line2),fp2);
if(lp1==line1 && lp2==line2)
{
if(strncmp(line1,line2,MAXLINE)!=0)
{
printf("first difference line:\nfile1:%s\nfile2:%s\n",line1,line2);
lp1=lp2=NULL;
}
}
else if(lp1!=line1 && lp2==line2)
{
printf("end of file.");
}
else if(lp1==line1 && lp2!=line2)
{
printf("end of second file2.");
}
}while(lp1==line1 && lp2==line2);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询