Warning

You're browsing the old v2.x documentation. This version is no longer maintained. Click here to go the v3.x documentation.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
strncpy [2019/05/22 22:00] neilsstrncpy [2019/05/23 08:32] neils
Line 5: Line 5:
   strncpy <string pointer destination>, <string pointer source>, <byte n>   strncpy <string pointer destination>, <string pointer source>, <byte n>
      
-The ''STRNCPY'' command is similar to ''[[STRCPY|STRCPY]]'', the difference is that ''STRNCPY'' will copy the first //n// characters only.+The ''STRNCPY'' command is similar to ''[[STRCPY|STRCPY]]'', the difference is that ''STRNCPY'' will copy the first //n// characters only. Copying will stop at the end of //source// even if //n// is greater than the length of //source//.
  
 Example: Example:
Line 21: Line 21:
  
   10 a$="hello world"   10 a$="hello world"
-  20 b$=right$(a$, 5)+  20 b$=mid$(a$, 4, 3)
   30 print b$   30 print b$
      
Line 29: Line 29:
   dim buffer![6]   dim buffer![6]
   b$ = @buffer!   b$ = @buffer!
-  strcpy b$, a$+(strlen!(a$)-5)+  strcpy b$, a$+4, 3
   print b$   print b$
      
-Both programs will output "world".+Both programs will output "o w".
      
 **Important note**: 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. **Important note**: 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.