Reading sequential data from your 5.25 inch floppy

Continued from here.

Once you have some sequential data in a file on your disk, you can write a program to read it back. How this is done, varies between different Commodore machines, and can be quite tricky. On the C128, it is as easy as writing the data. You have to remember the structure of the data you were writing – in my case one string, one integer and one string.

This is a new program (clear any existing program by typing NEW), and it is assumed that you have your floppy with the data you created in the earlier post.

Use OPEN to open a file, but this time, specify that you want to READ the sequential file TEST.DAT.

10 OPEN 1, 8, 2, "TEST.DAT,SEQ,READ"

Then, use INPUT# to read each stored record. Just remember the data types. PRINT# supports writing multiple records in one call, and INPUT# supports multiple reads. So instead of writing three lines, I can read three records in one line, like so:

20 INPUT#1, A$, B, C$

Use CLOSE to close the file.

30 CLOSE 1

These line will display the file content on screen:

40 PRINT A$
50 PRINT B
60 PRINT C$

And if everything is correct, you will now se this:

ONE STRING
 5
ANOTHER STRING

(The commands I use are available Commodore Basic 4.0 on Commodore PET, but I run Commodore Basic 7 on a C128.)

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll:

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Comments

Important information: If you have not commented before, your comment will be reviewed before it is published. This means that you will not see it immediately, but I have received it. This is not because I want to filter comments, but because I want to prevent spam and advertising.

Leave a Reply

Your email address will not be published. Required fields are marked *