Chapter
10
I
BASIC
Keywords
EOF
Function
E
OF(
buffer)
Detects the end of a file.
Buffer
is the number assigned
to
the file when you opened it. It
must access an open file.
This function checks
to
see whether all characters up
to
the end-
of-file marker have been accessed
so
that you can avoid "Input
past
end" errors during sequential input.
When used with sequential access files, EOF returns
0
(false),
when the end-of-file record has not been read yet, and
-1
(true),
when it has been read.
When used with direct access files, EOF returns
-1
(true) if the
last executed GET statement was unable
to
read an entire record
because of an attempt
to
read beyond the physical end
of
the file.
Sample
Program
The following sequence
of
lines reads numeric data from
&ta.txt
into the array
AO.
When the last data character in the file is
read. the EOF test in Line 30 is true.
so
the program branches
out
of
the disk access loop.
1470
DIM
A(100) 'ASSUMING THIS
1480 OPEN
"I",
1,
"data.txt"
1490
I%
=
0
1500
IF
EOF(1
1
THEN GOTO 1540
1510 INPUT#I,
A(I%)
1520
I%
=
I%
+
1
1530 GOTO 1500
1540 REM PROG. CONT. HERE AFTER
IS
A
SAFE VALUE
DISK
INPUT
150