STRCAT(3) | NetBSD Library Functions Manual | STRCAT(3) |
char *
strcat(char * restrict s, const char * restrict append);
char *
strncat(char * restrict s, const char * restrict append, size_t count);
The strncat() function appends not more than count characters where space for the terminating ‘\0' should not be included in count.
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));
August 11, 2002 | NetBSD 5.99 |