Stop calling fgetc at end of file.

Add a variable to track if we're at the end of the input file, and only
call fgetc if we're not there yet.