![]() |
![]() |
![]() |
C++ Reference: strncat()
strncat()
Declaration
char* strncat(char* cpDest, const char* kcpSrc, size_t qCount);
Description
This function appends the first "qCount" characters of the null-terminated string "kcpSrc" to "cpDest," unless the NULL character is encountered before "qCount" characters are appended. In the latter case, only the characters up to the NULL are appended. The resulting string is null-terminated and the function returns the pointer "cpDest."
Example
#include <cstdio>
#include <cstring>
int main()
{
char caSource[] = ".net";
// Allocate enough room for concatenation
char caDest[10] = "XoaX";
// The two strings before concatenation
printf("%s and %s before\n", caDest, caSource);
// Only append two chars
strncat(caDest, caSource, 2);
// The destination string after concatenation
printf("%s after\n", caDest);
return 0;
}
Output:
![]() |
![]() |
![]() |
| Home | | | Reference | | | Play Games! | | | Blog | | | Forum | | | Site Map | | | Contact Us |





