How EOF works
BlitzMax Forums/BlitzMax Beginners Area/How EOF works
| ||
Hi, just did some testing of when EOF gets set when reading files:Strict Local file:TStream = ReadFile("test.txt") Local l$ = ReadLine(file) If Eof(file) Then Print "EOF!" CloseStream(file) If you run the above code and stick a single line of text in a text file (doesn't matter if you press Enter at the end of the line) then the code will report EOF (End of File). This is DIFFERENT from languages like Delphi where EOF only get's set after you try to read another line and the read fails. This makes quite a bit of difference when coding your filereading loops because after you read the last value, EOF is already set, you don't need to read another line to set it. Be careful :-) |
| ||
EOF is true whenever the current position in a stream is equal to or larger then the size. Since these are both signed ints, you cannot use files larger than two gigabytes. |
| ||
From the comments in the code I would guess it works like this : Rem bbdoc: Get stream end of file status returns: True for end of file reached, otherwise False about: For seekable streams such as file streams, Eof generally returns True if the file position equals the file size. This means that no more bytes can be read from the stream. However, it may still be possible to write bytes, in which case the file will 'grow'.<br> <br> For communication type streams such as socket streams, Eof returns True if the stream has been shut down for some reason - either locally or by the remote host. In this case, no more bytes can be read from or written to the stream. End Rem Method Eof() Return Pos()=Size() End Method |
| ||
Ah yes, the help file doesn't have that much detail. |