This example is from the K&R book
#include
main()
{
long nc;
nc = 0;
while(getchar() != EOF)
++nc;
printf(\"%ld
The program will read EOF
only at the actual end of the input. If your terminal/OS/whatever only permit files to end at the start of a line then that's where you'll find them. I believe this is a throw-back to old-fashioned terminals where data was only transmitted a line at a time (for all I know it goes back to punched card readers).
Try reading your data from a file that you've preprepared with an EOF mid-line. You may even find that some editors make this difficult! Your program should work fine with that as input.