Jump to content
IGNORED

Strings in Atari Basic


kaneda23

Recommended Posts

  • 4 weeks later...

There is another thing that I didn't understand. Take the following code snippet:

10 DIM B$(384)

20 B$ = "X"

30 B$(384) = CHR$(0)

40 B$(2) = B$

 

The end result is that each byte of B$ contains an "X".

 

So, line 20 sets the first byte of B$ to "X" (or the ATASCII code for X). But, what is the purpose of line 30?

 

After line 30, the first byte of B$ is set to "X", and the 384th byte is set to 0. Can someone explain how line 40 sets each byte of B$ to "X"?

 

Thanks.

Link to comment
Share on other sites

It defines the very last byte in memory allocated to the string...setting the string length to the maximum...so that the copy process (B$(2)=B$) is consistantly grabbing the preceding value of the position that it is at currently...translating to the loop B$(2)=B$(1), B$(3)=B$(2) - which now contains the copy from 1, B$(4)=B$(3) - which now contains the value from 2, etc.

An interesting note is if this had been coded to run in reverse and copied strings from the top down, it wouldn't have worked. Serendipity, I guess :)

 

If this is not done, the resulting string would only be 2 bytes long (it would only be copying one byte in that case).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...