[Prev] [Next] [Contents] [Commodore] [New] [Search] [Home]

Consider the statement PRINT# 1, A$, B$, C$. When used with the screen, the commas between the variables provide enough blank space between items to format them into columns ten characters wide. On cassette, anywhere from 1 to 10 spaces will be added, depending on th length of the strings. This wastes space on your tape.

Even worse is what happens when the INPUT# statement tries to read these strings. The statement INPUT# 1, A$, B$, C$ will discover no data for B$ and C$. A$ will contain all three variables, plus the spaces between them. What happens? Here's a look at the tape file:

   A$="DOG" B$="CAT" C$="TREE"
   PRINT# 1, A$, B$, C$

   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
   D O G                 C  A  T                       T  R  E  E  RETURN

The INPUT# statement works like the regular INPUT statement. When typing data into the INPUT statement, the data items are separated, either by hitting the <RETURN> key or using commas to separate them. The PRINT# statement puts a RETURN at the end of a line just like the PRINT statement. A$ fills up with all three values because there's no separator on the tape between them, only after all three.

A proper separator would be a comma (,) or a RETURN on the tape. The RETURN code is automatically put at the end of a PRINT or PRINT# statement. One way to put the RETURN code between each item is to us only one item per PRINT# statement. A better way is to set a variable to the RETURN CHR$ code, which is CHR$(13), or use a comma. The statement for this is R$=",":PRINT#1, A$ R$ B$ R$ C$. Don't use commas or any other punctuation between the variable names, since the Commodore 64 can tell them apart and they'll only use up space in your program.

A proper tape file looks like this:

   1 2 3 4 5 6 7 8 9 10 11 12 13

   D O G , C A T , T  R  E  E  RETURN

The GET# statement will pick data from the tape one character at a time. It will receive each character, including the RETURN code and other punctuation. The CHR$(0) code is received as an empty string, not as a one character string with a code of 0. If you try to use the ASC function on an empty string, you get the error message ILLEGAL QUANTITY ERROR.


[Prev] [Next] [Contents] [Commodore] [New] [Search] [Home]
This page has been created by Sami Rautiainen.
Read the small print. Last updated May 26, 1998.