2 files - select each item in the second file and search for each matched item in the first file
when an item is found - print something - select next item in second file and search first file again from the beginning --- but the inner loop continues from where it found the last match - tried using break and continue keywords - but to no avail
the solution cannot be difficult but i'm having a dumb day
thanks in advance for and hints
file 1
-------------
pollock
cod
shark
haddock
minnow
hake
cod
goldfish
file 2
------------
haddock
cod
Code:
while(fgets(line2, sizeof line2, fin2)){
printf("outer loop reads = %s", line2);
while(fgets(line, sizeof line, fin)){
printf("inner loop read = %s", line);
countlines++;
if(strcmp (line2, line) == 0){
printf("\nFound %s on line %d\n", line2, countlines);
printf("line2 = %s and line = %s\n", line2, line);
break;
}
}
}
output
------------
outer loop reads = haddock
inner loop read = pollock
inner loop read = cod
inner loop read = shark
inner loop read = haddock
Found haddock
on line 4
line2 = haddock
and line = haddock
outer loop reads = cod
inner loop read = minnow
inner loop read = hake
inner loop read = cod
Found cod
on line 7
line2 = cod
and line = cod