strcpy function(String Copy) in C Language – example and detail

In the C Programming Language, the strcpy feature copies the string pointed to by s2 into the object pointed to via s1. It returns a pointer to the destination.


The syntax for the strcpy feature in the C Language is:

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

Parameters or Arguments

s1 An array where s2 will be copied to. s2 The string to be copied.


The strcpy function returns s1.

Required Header

In the C Language, the required header for the strcpy function is:

#include <string.h>

Applies To

In the C Language, the strcpy function can be used in the following versions:

ANSI/ISO 9899-1990

strcpy Example

Let’s seem at an example to see how you would use the strcpy characteristic in a C program:

/* Example using strcpy by */

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

int main(int argc, const char * argv[])
    /* Create an example variable capable of holding 50 characters */
    char example[50];

    /* Copy the string " knows strcpy!" into the example variable */
    strcpy (example, " knows strcpy!");

    /* Display the contents of the example variable to the screen */
    printf("%s\n", example);

    return 0;

When compiled and run, this software will output: knows strcpy!

Similar Functions

Other C features that are similar to the strcpy function:

memcpy feature memmove feature strncpy function