Program Stops Before completion

Started by Mikey, June 30, 2018, 23:49:07

Previous topic - Next topic

Mikey

In this source

FH1=OpenFile(FP$):FH2=WriteFile(FQ$)

While Not Eof(FH1)

BT=ReadByte(FH1)
Repeat

AW$=AW$+Chr$(BT):BT=ReadByte(FH1)
Until BT=32
WriteLine(FH2,AW$):AW$="":NW=NW+1
Wend
Print NW+" WRITTEN"


I'm reading from a file that has no <CR>, taking the bytes written up to a space, then writing that string to another file.
The program works fine until the 100,000th word or so, then it hangs up.
Is there some Caveat in BB that is doing this or am I too tired too spot the error?


Matty

It is reading beyond the end of file and the last character is not a byte 32 so it stays in the inner loop indefinitely

Mikey

#2
Nevermind I found the problem.
I was not checking for the read past the end of file. BT returns a zero then.

** You're right Matty.
The software evidently also buffers a portion before writing and so gives the notion that the program stopped well before the end of the list when it actually reached the end while not writing the buffered part.