Hi every body..
I've corrected my code in which I would like to compare strings of two txt files;
file1.txt=
054,8100,171
054,8100,191
file2.txt=
054,8100,171
054,8100,191
054,8100,171
054,8100,181
054,8100,171
054,8100,171
054,8100,171
to be as following:
Code:
untill this point, it's perfectly achieve comparing 1st string of file1 with all strings of file2...
but know, I want to compare the 2nd string of file1 with all string of file2.. and so on consecutively..
I would greatly appreciate it if I could get some assistance! Thanks in advance!
I've corrected my code in which I would like to compare strings of two txt files;
file1.txt=
054,8100,171
054,8100,191
file2.txt=
054,8100,171
054,8100,191
054,8100,171
054,8100,181
054,8100,171
054,8100,171
054,8100,171
to be as following:
Code:
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
void pError(char * s){
printf("%s\n",s);
}
int main(){
int equal_lines=0;
FILE *pt1,*pt2;
pt1=fopen("file1.txt","r");
if (pt1==NULL)
pError("open error f1");
pt2=fopen("file2.txt","r");
if (pt2==NULL)
pError("open error f2");
short q=0;
char c1[50],c2[50]; //declaring a string to hold the content of each file.
int buf_size=sizeof(c1);
fgets(c1,buf_size,pt1);
while(((fgets(c2,buf_size,pt2))!= NULL)&&(!q))
{
printf("f1: %s\n",c1);
printf("f2: %s\n",c2);
if(strcmp(c1,c2)==0)
equal_lines++;
}
printf("\n\n equal_lines=%d",equal_lines);
getch();
return 0;
}
but know, I want to compare the 2nd string of file1 with all string of file2.. and so on consecutively..
I would greatly appreciate it if I could get some assistance! Thanks in advance!
Comment