I have two text file as;
Andrew Hall
Arnold Price
Shelley Baker
and,
Arnold Hill
Veronica Clay
As you can see they are ordered. I need to combine them into another text file which is ordered again. So, expected output is;
Andrew Hall
Arnold Hill
Arnold Price
Shelley Baker
Veronica Clay
However, the output shows up as;
Andrew Hall
Arnold Hill
Arnold Price
I think somehow I am losing last lines of both files and both fsort1 and fsort2 reach end of their files. How can I find a general solution? What am I doing wrong?
My code is like that;
fgets(name1, 100, fsort1);
fgets(name2, 100, fsort2);
while(!feof(fsort1) || !feof(fsort2)){
if(strcmp(name1, name2)<0){
fprintf(foutput, "%s", name1);
fgets(name1, 100, fsort1);
}
else{
fprintf(foutput, "%s", name2);
fgets(name2, 100, fsort2);
}
}
Thank you.