BASIC-80

Disk File Input/Output

LINE INPUT, on the other hand, ignores blanks, commas, and quotation marks, and reads everything between the current file position and the next carriage return- line feed, or up to 255 characters. If the last INPUT did not read to the end of a logical line, LINE INPUT will read to the end of that line before reading the next line. The string is assigned to the single string variable specified. In the preceding ex- ample, assume that instead of the INPUT statement shown, the following statement was executed:

LINE INPUT #2,R$

The value of R$ would be:

"R1" ,200, "R2" ,2200, "R3" ,10000

This statement is useful for reading from a file that consists of lines, not individual data values, such as lines from an ASCII-saved BASIC-80 program file, or a docu- ment created with the ISIS-II text editor.

The INPUT$ function reads the specified number of characters from a sequential file:

10OPEN "1",#1,":F1:MONTHS"

20PRINT INPUT$ (3,1)

30CLOSE #1

40END

This program reads the first 3 characters from the file :Fl :MONTHS and prints them. If you execute line 20 again, INPUT$ will read the next 3 characters.

When you read the last value from a file, an end-of-file flag is set to -1.This flag can be tested with the EOF function. If you try to read data from a disk file after the end-of-file flag is set, BASIC-80 issues an INPUT PAST END message and execu- tion halts. To prevent surprises, you can test for an end-of-file with the EOF func- tion and then branch to an appropriate routine:

250 IF EOF (1) THEN 300

300 CLOSE 1

310 PRINT "END OF INPUT DATA"

Closing a Sequential File

Once you read or write the desired data from or to a sequential file, you must close the file. This can be done in several ways.

The CLOSE command closes one or more files:

CLOSE 1,2,5

If you enter CLOSE with no file number, all open files are closed. The END state- ment and the NEW and EXIT commands close all disk files. After closing a file, you can open it again for input or output, with the same or a different file number.

5-3

Page 35
Image 35
Intel 9800758-02 manual Closing a Sequential File, Value of R$ would be