STRCPY

Syntax:

strcpy <string pointer destination>, <string pointer source>

The STRCPY command copies the string pointed by source (including the null character) to the string pointed by destination.

Example:

dim buffer![16]
a$ = "xc=basic"
b$ = @buffer!
strcpy b$, a$
print b$
rem -- the above will output "xc=basic"

STRCPY can be used to emulate the CBM BASIC function RIGHT$. Here is an example:

CBM BASIC code:

10 a$="hello world"
20 b$=right$(a$, 5)
30 print b$

XC=BASIC code:

a$ = "hello world"
dim buffer![6]
b$ = @buffer!
strcpy b$, a$+(strlen!(a$)-5)
print b$

Both programs will output “world”.

Important note: even if source is longer than destination, the routine will not stop copying at the end of destination which may lead to an overflow situation. You have to make sure that there is enough memory at the destination.

Note: you can't copy a string using $a=$b. Refer to the strings article to learn why.