Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

strcpy - Copy string

&pagelevel(4)&pagelevel

Definition   

#include <string.h>

char *strcpy(char *s1, const char *s2);

strcpy copies string s2 (including the null byte (\0)) to string s1. s1 must be long enough to
accept string s2 (including the null byte (\0)).

Return val.

Pointer to the result string s1.

Notes

Strings terminated with the null byte (\0) are expected as arguments.

strcpy does not check whether s1 is large enough for the result. If s1 is less than s2
(including the null byte), the result is a string that is not terminated with the null byte!

The behavior is undefined if memory areas overlap.

Example

The following program outputs the contents of s1 and s2, then calls strcpy and outputs both contents again.

#include <stdio.h>
#include <string.h>
int main(void)
{
    char s1[] = "Anne is pretty !";
    char s2[] = "Mary too !";
    printf("Contents s1: %s\nContents s2: %s\n", s1, s2);
    strcpy(s1, s2); /* copy s2 to s1 */
    printf("After strcpy:\nContents s1: %s\nContents s2: %s\n", s1, s2);
    return 0;
}

See also

strncpy