2.1.2.57 strncpy
Description
Copy characters of one string to another.
Syntax
LPSTR strncpy( 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.
- 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, without 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 strncpy_ex1()
{
string str1 = "Hello World!";
char szStr[80];
strncpy(szStr, str1, 5);
out_str(szStr); // Should be "Hello"
}
Remark
See Also
Header to Include
origin.h
Reference