In C, strcpy() copies a whole C-string into another array, including the ending '\0', so the destination holds the same text.
You pass the destination and the source. Both are required. The destination must already be large enough for every character plus '\0'. Include <string.h>.
Syntax
Pass the destination, then the source. Start with this call.
C
strcpy(dest, "Hello");
Call
What it does
strcpy(dest, "Hello")
Copies Hello and the ending '\0' into dest.
Include <string.h>. The call does not grow the destination array.
Library declarations
C
char *strcpy(char *dest, const char *src);
Parameters
Parameter
Description
dest
Required. The array you copy into. It must already be large enough.
src
Required. The C-string you copy from. It is not changed.
Return Value
Return Value
Description
dest pointer
The same destination pointer you passed in.
C Examples
Example 1 — Basic String Copy
Copy a literal into a char array large enough for the text and '\0'.