void filecomp(char f1[], char f2[])
{
FILE *fp1;
FILE *fp3;
char line1[MAX], line2[MAX];
char *s1, *s2;
int ctr, octr, a=0, b=1;
int i,count1=0, count2=1, count3=0, count4=0;
if((fp1 = fopen(f1, "rb")) == 0)
{
perror("fopen1");
}
if((fp3 = fopen(f2, "rb")) == 0)
{
perror("fopen2");
exit(1);
}
while( ((s1=fgets(line1,MAX,fp1)) != NULL) ) {
count1++;
while( (s2=fgets(line2,MAX,fp3)) != NULL ) {
i=strcmp( s1, s2 );
if( i == 0 ) {
count3++;
}
count2++;
}
if( count3==0 )
printf("line %d of file1 does not match lines of file3\n", count1 );
count2=1;
count3=0;
fseek( fp3, 0, SEEK_SET );
}
if( (s2=fgets(line2,MAX,fp3)) != NULL )
printf( "both files have ended\n" );
} |