Skip to main content
Open topic with navigation CAPL Functions » General » Function Overview » strncpy

strncpy

Valid for: CANoe DE • CANoe:lite DE • CANoe4SW DE • CANoe4SW:lite DE

Function Syntax

void strncpy(char dest[], char src[], long max);

Description

This function copies src to dest. max indicates the size of dest in bytes. The function ensures that there is a terminating ‘\0’. Thus, a maximum of max-1 bytes are copied. Note: A character may need several bytes depending on the string encoding, e.g. Japanese characters in Windows ANSI (932) encoding or any special characters in UTF-8 encoding. In that case, you should use mbstrncpy instead.

Parameters

  • dest: Destination buffer
  • src: Source string
  • max: Is used to determine the maximum number of copied bytes. Must not be larger than the size of dest. A maximum of max-1 bytes are copied. If src is shorter than that, bytes are only copied until a terminating ‘\0’ is encountered.

Return Values

Example

variables {
    char s1[7] = "Vector";
    char s2 [32];
}
on key 'z'
{
    strncpy (s2,s1,elcount(s2));
    write ("Result: %s",s2);  // Result: Vector
}
strlenstrncatstrncmpstrncpy_off