Code:
int comparefiles(const char *filename1,const char *filename2, int
x);
int countlines(const char *filename);
#include
<stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int i=0,j=0,cmpx,nl1=0,nl2=0,dt;
char
buffer[25000]={},buffer1[25000]={}, buffero[25000]={};
FILE *output;
char
buf[20000]={};
char buf1[20000]={};
char bufo[20000]={};
char
string2[]="/COND.txt";
char string[]="rctcas.txt";
//char
string[]="TEST";
for(i=0;i<1;i++)
{
sprintf(buf,"/home/csgrads/akhan015/desktop/programs/benchmarks/tcas/coverage/test1260%s",string2);
printf("reading
reference file %s
\n",buf);
for(j=0;j<=1589;j++)
{
sprintf(buf1,"/home/csgrads/akhan015/desktop/programs/benchmarks/tcas/coverage/test%d%s",
j,string2);
printf("reading inner loop %s \n",buf1); //sending reference file
and another file to compare
dt=comparefiles(buf,buf1,j);
}
}
return
0;
}
int countlines(const char *filename) //count no of
lines
{
FILE *fm;
char line[1024];
int NumberOfLines =
0;
fm=fopen(filename, "r");
while( fgets(line,sizeof(line),fm) !=
NULL)
NumberOfLines++;
return(NumberOfLines);
fclose(fm);
}
int
comparefiles(const char *filename1,const char *filename2, int x)
{
FILE *
fref;
FILE *output;
FILE * myfile1;
char bufo[20000]={};
char
cx1[10000]={} ,cx2[10000]={},cx3[10000]={};
int cmpx,cmpx1;
signed int
s=-1;
int nl1,nl2,nl3;
//fflush(fref);
fref= fopen(filename1,
"r");
nl1=countlines(filename1);
myfile1=
fopen(filename2,"r");
nl2=countlines(filename2);
if((fref== NULL) ||
(myfile1== NULL))
printf("Error occurs in the file
\n");
else
{
int j = 0,
k=0;
rewind(myfile1);
first:
while((fgets(cx2 ,30 ,myfile1)!= NULL))
//choose strings and compare and stop when all the strings from //a file match
reference file, i.e. no unique string to add
{j++;
int i =
0;
rewind(fref);
while((fgets(cx1 ,30, fref)!=
NULL))
{
i++;
if((cmpx=strcmp(cx2 ,cx1))== 0)
{
k++;
if(k==(nl2))
{printf("%d=%d FILES ARE SAME\n",k,nl2
);
return;
}
goto
first;
}
}
if((j!=k)&&((cmpx=strcmp(cx2
,cx1))!= 0)) //here a different statement is found //and checked whether it has
been saved in rctcas during comparison with some other file
{
printf("
STATEMENT DOESNOT EXIST\n");
output=fopen("rctcas.txt","a+");
int
l=0;
nl3=countlines("rctcas.txt");
second:
while((fgets(cx3 ,30,
output)!= NULL))
{puts(cx2);
puts(cx3);
l++;
if((cmpx1=strcmp(cx2
,cx3))== 0)
{
return;}
else
if(l==nl3)
{fputs(cx2,output);
fclose(output);}
}
}
}
return;
}
i