MirBSD manpage: strcat(3), strncat(3)

STRCAT(3)                  BSD Programmer's Manual                   STRCAT(3)


     strcat, strncat - concatenate strings


     #include <string.h>

     char *
     strcat(char *s, const char *append);

     char *
     strncat(char *s, const char *append, size_t count);


     The strcat() and strncat() functions append a copy of the NUL-terminated
     string append to the end of the NUL-terminated string s, then add a ter-
     minating '\0'. The string s must have sufficient space to hold the

     The strncat() function appends not more than count characters where space
     for the terminating '\0' should not be included in count.


     The strcat() and strncat() functions return the pointer s.


     The following appends "abc" to chararray:

           char *letters = "abcdefghi";

           (void)strncat(chararray, letters, 3);

     The following example shows how to use strncat() safely in conjunction
     with strncpy(3).

           char buf[BUFSIZ];
           char *input, *suffix;

           (void)strncpy(buf, input, sizeof(buf) - 1);
           buf[sizeof(buf) - 1] = '\0';
           (void)strncat(buf, suffix, sizeof(buf) - 1 - strlen(buf));

     The above will copy as many characters from input to buf as will fit. It
     then appends as many characters from suffix as will fit (or none if there
     is no space). For operations like this, the strlcpy(3) and strlcat(3)
     functions are a better choice, as shown below.

           (void)strlcpy(buf, input, sizeof(buf));
           (void)strlcat(buf, suffix, sizeof(buf));


     bcopy(3), memccpy(3), memcpy(3), memmove(3), strcpy(3), strlcat(3),


     The strcat() and strncat() functions conform to ANSI X3.159-1989 ("ANSI

MirBSD #10-current               July 8, 1997                                1

Generated on 2022-12-24 01:00:14 by $MirOS: src/scripts/roff2htm,v 1.113 2022/12/21 23:14:31 tg Exp $ — This product includes material provided by mirabilos.

These manual pages and other documentation are copyrighted by their respective writers; their sources are available at the project’s CVSweb, AnonCVS and other mirrors. The rest is Copyright © 2002–2022 MirBSD.

This manual page’s HTML representation is supposed to be valid XHTML/1.1; if not, please send a bug report — diffs preferred.

Kontakt / Impressum & Datenschutzerklärung