The strcpy()
function is a built-in library function, declared in the string.h header file. It copies the source string to the destination string until a null character (\0
) is reached.
char * strcpy (char * Dest, char * Src);
strcpy()
takes two strings as arguments and character by character (including \0
) copies the content of string Src to string Dest, character by character.
Let’s look at an example of strcpy()
:
#include <stdio.h>#include <string.h>int main(){char Src[15]= "educative";char Dest[15] = "";printf("Before copying\n");printf("Source string: %s \n", Src);printf("Destination string: %s \n\n", Dest);strcpy(Dest, Src); // calling strcpy functionprintf("After copying\n");printf("Source string: %s \n", Src);printf("Destination string: %s \n", Dest);return 0;}
Free Resources