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.


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:


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.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies


Enter your comment. Wiki syntax is allowed: