lstrcpyn

 

Description

The lstrcpyn (alias strncpy) function copies a specified number of characters from a source string into a buffer.

Syntax

LPSTR lstrcpyn( LPSTR lpString1, LPCSTR lpString2, int iMaxLength )

Parameters

lpString1
[modify] Pointer to a buffer into which the function copies characters. The buffer must be large enough to contain the number of characters specified by iMaxLength, including room for a terminating null character.
lpString2
[input] Pointer to a null-terminated string from which the function copies characters.
iMaxLength
[input] Specifies the number of characters to be copied from the string pointed to by lpString2 into the buffer pointed to by lpString1, including a terminating null character.

Return

If the function succeeds, the return value is a pointer to the buffer. If the function fails, the return value is NULL.

Examples

EX1

void lstrcpyn_ex1()
{
        char               *ptr = NULL;
        char        szStr[80];
        string      str1 = "Here is some text";
        ptr = lstrcpyn(szStr, str1, 5);
        if(0 == strcmp(ptr, "Here") )
                printf(" after copy szStr is  \"%s\" \n" , szStr);
        else
                printf("copy failed\n");
}

Remark

See Also

lstrcpy

header to Include

origin.h

Reference