Question #6704   Submitted by Answiki on 09/21/2022 at 06:17:38 PM UTC

In C, how to copy a string into another string?

Answer   Submitted by Answiki on 09/21/2022 at 06:40:53 PM UTC

In C, the purpose of the strcpy() (string copy) function is to copy a string into another:

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

Library: the strcpy() function needs the string.h library:

#include <string.h>

Note that the size of the destination string must be large enough to accommodate the copy.


Example :

// Source string
char src[] = "String to copy";
// Destination string
char dest[200];
// Copy src in dest 
strcpy (dest, src);

Try online on repl.it.

6 events in history
Question by Answiki 09/21/2022 at 06:41:45 PM
In C, how does the strcpy() function work?
Question by Answiki 09/21/2022 at 06:41:38 PM
In C, how does the strcpy function work?
Answer by Answiki on 09/21/2022 at 06:40:53 PM

In C, the purpose of the strcpy() (string copy) function is to copy a string into another:

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

Library: the strcpy() function needs the string.h library:

#include <string.h>

Note that the size of the destination string must be large enough to accommodate the copy.


Example :

// Source string
char src[] = "String to copy";
// Destination string
char dest[200];
// Copy src in dest 
strcpy (dest, src);

Try online on repl.it.

Answer by Answiki on 09/21/2022 at 06:40:42 PM

In C, the purpose of the strcpy() (string copy) function is to copy a string into another:

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

Library: the strcpy() function needs the string.h library:

#include <string.h>

Note that the size of the destination string must be large enough to accommodate the copy.


Example :

// Source string
char src[] = "String to copy";
// Destination string
char dest[200];
// Copy src in dest 
strcpy (dest, src);

Tester l'exemple en ligne sur repl.it.

Answer by Answiki on 09/21/2022 at 06:25:11 PM

In C, the purpose of the strcpy (string copy) function is to copy a string into another:

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


Library: this function needs the string.h library:

#include <string.h>

Note that the size of the destination string must be large enough to accommodate the copy.


Example :

// Source string
char src[] = "String to copy";
// Destination string
char dest[200];
// Copy src in dest 
strcpy (dest, src);

Tester l'exemple en ligne sur repl.it.

Question by Answiki 09/21/2022 at 06:17:38 PM
In C, how to copy a string into another string?
# ID Query URL Count

Icons proudly provided by Friconix.