![]() |
![]() |
![]() |
C++ Reference: strncpy()
strncpy()
Declaration
char* strncpy(char* cpDest, const char* kcpSrc, size_t qCount);
Description
This function copies the first "qCount" characters of "kcpSrc" to "cpDest." The function returns the pointer "cpDest."
Example
#include <cstdio>
#include <cstring>
int main()
{
char caSource[] = "XoaX.net";
char caDest[20];
// Copy the first chars of "XoaX.net"
strncpy(caDest, caSource, 4);
// Add a null-terminator for printing
caDest[4] = '\0';
printf("Copied: %s\n", caDest);
return 0;
}
Output:
![]() |
![]() |
![]() |
| Home | | | Reference | | | Play Games! | | | Blog | | | Forum | | | Site Map | | | Contact Us |





