stpcpy
string return-offset-pointer copy
- Provided by: manpages-dev (Version: 6.18-1)
- Source: manpages
- Report a bug
string return-offset-pointer copy
Standard C library (libc, -lc)
#include <string.h>
char *stpcpy(char *restrict dst, const char *restrict src);
stpcpy():
Since glibc 2.10:
_POSIX_C_SOURCE >= 200809L
Before glibc 2.10:
_GNU_SOURCE
stpcpy() is similar to strcpy(3), but returns a pointer to the terminating null byte in dst.
It is equivalent to both of the following expressions:
memset(mempcpy(dst, src, strlen(src)), '\0', 1); strcpy(dst, src) + strlen(src)
This function returns a pointer to the terminating null byte of the copied string.
For an explanation of the terms used in this section, see attributes(7).
| Interface | Attribute | Value |
| stpcpy () | Thread safety | MT-Safe |
POSIX.1-2008.
POSIX.1-2008.
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
main(void)
{
char *p;
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()");
p = buf1;
p = stpcpy(p, "Hello ");
p = stpcpy(p, "world");
p = stpcpy(p, "!");
len = p - buf1;
printf("[len = %zu]: ", len);
puts(buf1); // "Hello world!"
free(buf1);
exit(EXIT_SUCCESS);
}
strcpy(3), strdup(3), string(3), wcpcpy(3), string_copying(7)