Author Topic: EOF with INPUT/BINARY  (Read 2921 times)

0 Members and 1 Guest are viewing this topic.

Offline TheGuardHQ

  • Newbie
  • Posts: 6
    • View Profile
EOF with INPUT/BINARY
« on: December 04, 2018, 02:40:43 am »
Hello everybody!

I have a question about EOF.

If I create a blank file and then read this with "INPUT", this works without error message:

OPEN "c:\temp\test.txt" FOR OUTPUT AS #1: CLOSE
OPEN "c:\temp\test.txt" FOR INPUT AS #1
DO WHILE NOT EOF(1)
    LINE INPUT #1, zeile$
LOOP
CLOSE #1


If I do the same thing with
  OPEN "c:\temp\test.txt" FOR BINARY AS #1
I get the error message "Input past end of file".

Can someone tell me how to write the DO-LOOP so I do not run into the EOF error?

Christian

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: EOF with INPUT/BINARY
« Reply #1 on: December 04, 2018, 02:59:45 am »
DO WHILE LOF(1) AND NOT EOF(1)

I'd imagine the above should work (I haven't tested it), but by adding the LOF() check, you should skip the loop completely if it's a 0-byte file.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: EOF with INPUT/BINARY
« Reply #2 on: December 04, 2018, 03:45:38 am »
Yep, Steve nailed it. Just change...

DO WHILE NOT EOF(1)

to

DO WHILE LOF(1) AND NOT EOF(1)

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline TheGuardHQ

  • Newbie
  • Posts: 6
    • View Profile
Re: EOF with INPUT/BINARY
« Reply #3 on: December 04, 2018, 09:15:29 am »
Thank you - that was the solution.

Christian