Your problem is here:
while(!feof(joker2))
{
fgets(data,1000,joker2);
printf("%s",data);
}
feof()
returns
true
only
after an EOF has been read. What is happening in your case is that
fgets()
reads up to and including the last
'\n'
in the file. At this point
feof()
is still false, since no EOF has been seen. At the next call to
fgets()
, the EOF condition is set, and
data
is unchanged. You then print data again, and then end the loop because
now feof()
is true. To solve this use the following:
while(true)
{
fgets(data, 1000, joker2);
if(feof(joker2)
break;
printf("%s", data);
}