QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: Dimster on March 22, 2020, 10:30:52 am
-
I have large program which Opens 50 files at once and attempts to input the data. The data files vary in length/quantity of data they hold. Seems I invariable run into the end of one of these files more often that not and I was wondering which of the following algorythms works the most reliably:
For x = 1 to 50
while NOT EOF (x)
Input #x, A,B,C
or
For x = 1 to 50
While EOF(x) = 0
Input #x, A,B,C
or
For x = 1 to 50
While EOF(x)<>-1
It's not really practical for me to put a dummy value at the end of each file.
-
You can't open and close them sequentially and store all their data in an array for faster access?
-
Not quite sure what you are asking here bplus. The 50 files are all open at once. The input #x, is in a DO loop which does read each one sequentially right to the end of the file. As each files' data is read, there are other routines (mostly calculations) which work on the data before the next open file is addressed. The data within each file is NOT stored in Arrays, and perhaps that could provide faster access but for now the accuracy of the calculations is my main concern.
You have me rethinking the error I'm running into. Every now and then I am running into an input past end of file which had me thinking I'm search for the wrong end of file marker, but maybe the problem is that all the files are not of equal length, or that I'm misreading the error code. Back to the drawing board.
-
To prevent going past the end of file you could you use LOC to give the current byte position in an open file and LOF to give the file size in bytes.
Then keep reading the file while LOC(filenum%) <= LOF(filenum%).
Edited to make the comparison "Less than or equal to".
-
Thanks EricE, I'll give it a try.
-
You are welcome Dimster.
You probably should make the check "Less than or equal to" in order to get the last byte of the file.
-
DO UNTIL EOF(x)
LINE INPUT #x, A, B, C
LOOP
-
DO UNTIL EOF(x)
LINE INPUT #x, A, B, C
LOOP
+1
-
Thanks very much guys