C Programming Tutorial
Computer Tutorial

strcpy( ) Function

strcpy( ) Function

This function copies the contents of one string into another. The base addresses of the source and target strings should be supplied to this function.

Program to demonstrate strcpy() function

\* C Program to demonstrate strcpy() function *\

# include < stdio.h >
int   main( )

char   source[ ] = "General note"  ;
char   target[25]  ;
strcpy(  target, source) ;
printf(" \nsource string = %s ",  source) ;
printf(" \ntarget string = %s ",  target) ;
return ( 0 ) ;


Output :

source string = Generalnote
target string = Generalnote

On supplying the base addresses, strcpy( ) goes on copying the characters in source string into the target string till it doesn't encounter the end of source string (‘\0’). It is our responsibility to see to it that the target string’s dimension is big enough to hold the string being copied into it. Thus, a string gets copied into another, piece-meal, character by character.