Skip to main content

mbstrncpy, mbstrncpy_off

Open topic with navigation CAPL Functions » General » Function Overview » mbstrncpy, mbstrncpy_off

Function Syntax

void mbstrncpy(char dest[], char src[], long len);
void mbstrncpy_off(char dest[], long destOffset, char src[], long len);

Description

mbstrncpy function copies src to dest. len indicates the number of characters that shall be copied; use -1 to indicate that as much shall be copied into dest as will fit (maximum until the end of src). The function ensures that there is a terminating 0 byte; but in contrast to strncpy, that byte is not counted into len. mbstrncpy_off overwrites characters in the destination buffer starting at the character offset destOffset.

Parameters

  • dest: Destination buffer
  • src: Source string
  • len: Number of characters to be copied, or -1 to copy as much as possible
  • destOffset: Offset in characters into the destination buffer

Return Values

Example

char s1[50] = "eine grüne "; // german for 'a green'
char s2[10] = "Türen"; // german for 'doors'
mbstrncpy_off(s1, 11, s2, 3);
write("%s", s1); // eine grüne Tür (german for 'a green door')