<string.h> Functions

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.

The function also returns the copied array.

The strcpy() function is defined in the 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");

    return 0;



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