I think it reads input file wrongly...
input past end of file mostly occurs when there is and eof character within the content of the file

this can be resolved by opening the file for binary instead of input, as eof characters are just read as part of the file

alteratively if you know how many lines are in the input file, you can just loop for that number of lines, instead of until eof

for i = 1 to numberoflines