NAME

eof - end-of-file function

SYNOPSIS

v = eof(FileNum)

DESCRIPTION

The eof function returns a value of -1 (true) if the end of the specified file has been reached, i.e. if reading from the file would cause an attempt to read beyond the end of the file.  Eof returns a zero (false) if the end of the file hasnít been reached.  If the file is a terminal, eof always returns zero (false). 

The eof function should be used to avoid an "Input past end" error. 

FileNum may be any numeric expression.  Its value should match the FileNum given in the open statement for the file being checked. 

In support of pipes (see open), this function closes the output side of a pipe (if any) and tests for termination of the program to which the pipe is connected.  The output pipe is closed to allow the program to stop reading and processing data; therefore this function may used only after all data has been output to the program.  The best test for end-of-file from a pipe connected to a program is termination of the program.  Thus for pipes, this function really tests for termination of the program as a sure test of end-of-file on the pipe. 

EXAMPLE

The program
	open "infile" for input as #1
	while not eof(1)
		input #1, a$
		print a$
	wend
reads strings from the sequential file "infile".  Values are read and printed until end of file is reached. 

The program

	open "pipe: sort -t# +1" as #1
	line input a$
	while a$ <> "END"
		print #1, a$
		line input a$
	wend
	while not eof(1)
		if lof(1) then line input #1, a$: print a$
	wend
compiled and run with a data file such as "name.number":
	$ cat name.number
	Clive Land #(216) 555-1212
	Hugh Ston #(713) 555-1212
	Phil Adelphia #(215) 555-1212
	Sandy Ego #(619) 555-1212
	END
	$ a.out < name.number
	Phil Adelphia #(215) 555-1212
	Clive Land #(216) 555-1212
	Sandy Ego #(619) 555-1212
	Hugh Ston #(713) 555-1212
	$
sorts a list of phone numbers (introduced by pound signs) using the UNIX sort utility.  Note that the eof function is used not only to determine that the sort utility has finished sending data, but also to close the output side of the pipe which signals the utility to begin sorting. 

SEE ALSO

open

DIAGNOSTICS

If FileNum is less than 0 or greater than the number of files allowed, a "Bad file number" error occurs. 

If FileNum indicates a file that is open for output only, a "Bad file mode" error occurs. 

from The Basmark QuickBASIC Programmerís Manual by Lawrence Leinweber