Defined in header
char *strcpy( char *dest, const char *src );
char *strcpy( char *restrict dest, const char *restrict src );
errno_t strcpy_s(char *restrict dest, rsize_t destsz, const char *restrict src);
src, including the null terminator to the character array whose first element is pointed to by
dest. The behavior is undefined if the
destarray is not large enough. The behavior is undefined if the strings overlap.
destis a null pointer
destszis zero or greater than RSIZE_MAX
destszis less or equal strnlen_s(src, destsz), in other words, truncation would occur
- overlap would occur between the source and the destination strings
- As all bounds-checked functions,
strcpy_sis only guaranteed to be available if __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including
|dest||-||pointer to the character array to write to|
|src||-||pointer to the null-terminated byte string to copy from|
|destsz||-||maximum number of characters to write, typically the size of the destination buffer|
 Return value
destis a null pointer or
destszis zero or greater than RMAX_SIZE).
strcpy_s is allowed to clobber the destination array from the last character written up to
destsz in order to improve efficiency: it may copy in multibyte blocks and then check for null bytes.
strcpy_s is similar to the BSD function
strlcpy, except that
strlcpytruncates the source string to fit in the destination (which is a security risk)
strlcpydoes not perform all the runtime checks that
strlcpydoes not make failures obvious by setting the destination to a null string or calling a handler if the call fails.
strcpy_s prohibits truncation due to potential security risks, it's possible to truncate a string using bounds-checked strncpy_s instead.
src = Take the test. dst = Make the test.
- C11 standard (ISO/IEC 9899:2011):
- 22.214.171.124 The strcpy function (p: 363)
- K.126.96.36.199 The strcpy_s function (p: 615-616)
- C99 standard (ISO/IEC 9899:1999):
- 188.8.131.52 The strcpy function (p: 326)
- C89/C90 standard (ISO/IEC 9899:1990):
 See also
| copies a certain amount of characters from one string to another |
| copies one buffer to another |
| copies one wide string to another |
C++ documentation for strcpy