C strcpy()

The strcpy() function copies the string to the another character array.

strcpy() Function prototype

char* strcpy(char* destination, const char* source);

The strcpy() function copies the string pointed by source (including the null character) to the character array destination.

This function returns character array destination.


The strcpy() function is defined in string.h header file.


Example: C strcpy()

#include <stdio.h>
#include <string.h>

int main()
{
    char str1[10]= "awesome";
    char str2[10];
    char str3[10];

    strcpy(str2, str1);
    strcpy(str3, "well");
    puts(str2);
    puts(str3);

    return 0;
}

Output

awesome
well

It is important to note that, the destination array should be large enough otherwise it may result in undefined behavior.