I am writing a program to compare two files. If matching lines occur then the program will continue to do some task. My second file has only one line and the first file has several lines
Contents of File_1
apple is red
oranges are orange
banana is yellow
cat is black
red is not green
Contents of File_2
cat is black
I have used fscanf
function to read the lines of File_2 and store it in a variable.
if ((fp=fopen(File_2, "r")) == NULL)
{
printf("Error opening File");
}
fscanf(fp,"%[^\n]", name);
fclose(fp);
I have used the following method to search for similarities in File_1
fp = fopen(File_1, "r");
while ((read = getline(&line, &len, fp)) != -1)
{
if (strcmp(line,name)==0)
{
printf("Hurray\n");
break;
}
else
{
printf("I am unlucky\n");
}
}
fclose(fp);
But my issue is that,
strcmp()
is not returning0
I was wondering what went wrong here. Any suggestions would be appreciated.