QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: TheGuardHQ on December 04, 2018, 02:40:43 am

Title: EOF with INPUT/BINARY
Post by: TheGuardHQ 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
Title: Re: EOF with INPUT/BINARY
Post by: SMcNeill 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.
Title: Re: EOF with INPUT/BINARY
Post by: Pete 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
Title: Re: EOF with INPUT/BINARY
Post by: TheGuardHQ on December 04, 2018, 09:15:29 am
Thank you - that was the solution.

Christian