I always reverse the two function calls:
while(fgets(line,MAXLINE,archlog))
{ if(feof(archlog))
break;
else
printf("%s",line);
}
That gets me out when the end of file is read. Sometimes I 'or' in ferror(archlog)
to the feof()
call, to break out on error or EOF.