C Standard Libraries C++

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

strncat() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.