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
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
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.