Program never finds EOF :(
Blitz3D Forums/Blitz3D Programming/Program never finds EOF :(
| ||
If I create a file using command prompt or some other slightly unsual method it seems that Blitz never finds the EOF it's expecting and so never stops reading the file. e.g. Create a simple text file by typing dir>d.txt [code] myfile=readfile("d.txt") While a$<>EoF a$=readline$(myfile) wend The program will never stop. Is there a simple solution to this problem? Darkheart |
| ||
While a$<>EoF a$=readline$(myfile) wend...should be... While a$<>EoF(myfile) a$=readline$(myfile) wend...should it not? Last edited 2012 |
| ||
Indeed. In the first example, EoF is an implicit-integer variable (BlitzMax users, remember: B3D is 1. non-Strict, and 2. has separate namespaces for variables and functions). |
| ||
Thanks, I have tried that but the prog still just goes round and round never exiting about it's done well over 20000 loops even the though file it is readin is only 20 lines long. Not sure what I'm doing wrong but I seem to remember something about the EoF charecter being different when you run stuff from the command line or something and Blitz doesn't recognise this. Or maybe that was a dream... I've put a copy of the file (simply created with the method above) and the blitz file code here (it's a .bb file and one .txt file): http://www.owenclark.info/bb/comp.zip I could set it to look for "" but that can occur to often in the file. Darkheart Last edited 2012 |
| ||
Well the second thing is that, checking the EoF documentation, it doesn't work that way. Just use it on the file and it returns the true/false value by itself (i.e. "While Not EoF(myFile)"). Comparing EOF to something read from the stream is the C way of doing things, and doesn't really make sense in B3D since it refers to character values, whereas B3D has strings that can hold any binary data. |
| ||
I use it this way :FileName$ = "BlahBlah.ext" File = ReadFile(FileName$) While Not(Eof(File)) LineString$ = ReadLine(File) Wend |
| ||
Remid/Yasha, thanks that's just what I needed to do! Cheers guys. Darkheart |
| ||
Yeah, EoF returns a True/False (1 / 0 ) result with the FileStream handle as a parameter. So something like: If (a$<>EoF(Stream)) Is only going to return True if a$ just happens to be "0" (when EoF not reached) or "1" When EoF is reached. The 'correct' interpretation ought to compare EoF(Stream) as a True/False boolean operation : If (EoF(Stream)) DebugLog("End Of File") Exit End If Or... While (StreamValid=True) Byte=ReadByte(Stream) If (Byte=0) StreamValid=False Else StreamValid=Not(EoF(Stream)) End If Wend etc. |