Specifications
220 num_of_data = 0 ! we'll count # data items per record
230 input #2, rec=recnum, data_itera$ ! only this 'input#' has a 'rec='
240 while data_item$ <> chr$(255) ! input until terminator character
250 num_of_data = num_of_data + 1
260 print tab(10*num_of_data-9); data_item$;
270 input #2, data_item$ ! note that this item still comes from
280 endloop ! same record (i.e. record #recnum)
290 print tab(51); "# items in record"; recnum;"="; num_of_data
300 next recnum
310 close #2:stop ! I suggest SAVEing this program
The program keeps inputting data items from a record until it encounters a chr$
(255).
Another way is to store the number of data items in a record at the start of the
record itself. We'll create such a file by modifying two lines in program 1; the
new lines should read as shown below. (Note: line 450 also stores the record #
at the start of each
450 print #2, rec=recnum, recnum; c$; num_items; c$; record.) Before running
490 print #2 the new program (called
#3), scratch the old
file by typing 'scratch "(f:60)examples,rel"'. I emphasize that you must ALWAYS
refer to a relative file by its full name, '(f:60)’ and all, or horrible things
can happen.
Program 4 reads the new data file (in reverse order, for variety). You'll notice
that it is actually a bit faster than program 2, despite having to read one more
piece of data per record, so I'd give this method the edge:
Program 4
600 open #2, "(f:60)examples,rel", input
610 for recnum = 18 to 3 step -1 ! read in reverse order
620 input #2, rec=recnum, filerecnum, num_of_data ! read first 2 data
630 print filerecnum; tab(11); num_of_data;
640 for i = 1 to num_of_data ! read # items we know are there
650 input #2, data_item$
660 print tab(10*i+11); data_item$;
670 next i
680 print
690 next recnum
700 close #2:stop
I don't bother with error trapping in any of these programs, as SuperPET catches
most errors without being asked. (One error it won't catch— try to input more
items from a record than it contains and SuperPET gets the extra items from the
next record.) There is one special use of I0_STATUS: if you use GET# to read a
relative file, I0_STATUS changes from its usual value of 0 to 1 at the end of
each record. This is your only way to keep records distinct, as GET# cannot use
the 'rec=' clause. I prefer to take the whole record at a gulp with LINPUT#, and
avoid GET# entirely.
In the (frankly) unlikely event that you wish to break records up into a known
number of fields, each field containing an unknown number of data items, you can
use the LINPUT# statement. LINPUT# reads everything up to the end of a record
or up to a chr$(13) character, whichever comes first. In the following program,
we break each record into three fields:
SuperpPET Gazette, Vol.I No.11
-171-
December 1983/January 1984










