strcpy, strcat
copy or catenate a string
- Provided by: manpages-dev (Version: 6.18-1)
- Source: manpages
- Report a bug
copy or catenate a string
Standard C library (libc, -lc)
#include <string.h>
char *strcpy(char *restrict dst, const char *restrict src); char *strcat(char *restrict dst, const char *restrict src);
stpcpy(dst, src), dst
stpcpy(strnul(dst), src), dst
These functions return dst.
For an explanation of the terms used in this section, see attributes(7).
| Interface | Attribute | Value |
| strcpy (), strcat () | Thread safety | MT-Safe |
C11, POSIX.1-2008.
POSIX.1-2001, C89, SVr4, 4.3BSD.
The strings src and dst may not overlap.
If the destination buffer is not large enough, the behavior is undefined. See _FORTIFY_SOURCE in feature_test_macros(7).
strcat() can be very inefficient. Read about Shlemiel the painter.
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
main(void)
{
char *buf1;
size_t len, size;
size = strlen("Hello ") + strlen("world") + strlen("!") + 1;
buf1 = malloc(sizeof(*buf1) * size);
if (buf1 == NULL)
err(EXIT_FAILURE, "malloc()");
strcpy(buf1, "Hello ");
strcat(buf1, "world");
strcat(buf1, "!");
len = strlen(buf1);
printf("[len = %zu]: ", len);
puts(buf1); // "Hello world!"
free(buf1);
exit(EXIT_SUCCESS);
}
stpcpy(3), strdup(3), string(3), wcscpy(3), string_copying(7)