1STRCAT(3) Linux Programmer's Manual STRCAT(3)
2
3
4
6 strcat, strncat - concatenate two strings
7
9 #include <string.h>
10
11 char *strcat(char *dest, const char *src);
12
13 char *strncat(char *dest, const char *src, size_t n);
14
16 The strcat() function appends the src string to the dest string, over‐
17 writing the null byte ('\0') at the end of dest, and then adds a termi‐
18 nating null byte. The strings may not overlap, and the dest string
19 must have enough space for the result.
20
21 The strncat() function is similar, except that
22
23 * it will use at most n characters from src; and
24
25 * src does not need to be null-terminated if it contains n or more
26 characters.
27
28 As with strcat(), the resulting string in dest is always null-termi‐
29 nated.
30
31 If src contains n or more characters, strncat() writes n+1 characters
32 to dest (n from src plus the terminating null byte). Therefore, the
33 size of dest must be at least strlen(dest)+n+1.
34
35 A simple implementation of strncat() might be:
36
37 char*
38 strncat(char *dest, const char *src, size_t n)
39 {
40 size_t dest_len = strlen(dest);
41 size_t i;
42
43 for (i = 0 ; i < n && src[i] != '\0' ; i++)
44 dest[dest_len + i] = src[i];
45 dest[dest_len + i] = '\0';
46
47 return dest;
48 }
49
51 The strcat() and strncat() functions return a pointer to the resulting
52 string dest.
53
55 SVr4, 4.3BSD, C89, C99.
56
58 bcopy(3), memccpy(3), memcpy(3), strcpy(3), strncpy(3), wcscat(3),
59 wcsncat(3)
60
62 This page is part of release 3.25 of the Linux man-pages project. A
63 description of the project, and information about reporting bugs, can
64 be found at http://www.kernel.org/doc/man-pages/.
65
66
67
68GNU 2008-06-13 STRCAT(3)