Strcpy () function in C

Char * strcpy function (char * dest, const char * src) copies the string pointed to by src to dest.

Char * strcpy function (char * dest, const char * src) copies the string pointed to by src to dest.

Declare strcpy () in C

Here is the declaration for strcpy () in C:

 char * strcpy ( char * dest , const char * src ) 

Parameters

dest - This is the pointer to the array containing the newly copied string.

src - String to be copied.

Returns the value

This function returns a pointer to the dest destination string.

For example

The following C program illustrates the usage of strcpy () in C:

 #include #include int  main () { char  src [ 40 ]; char  dest [ 100 ];  memset ( dest , '' , sizeof ( dest ));  strcpy ( src , "Hoc C co ban va nang cao tai QTM !!!" );  strcpy ( dest ,  src );  printf ( "Sau khi thuc hien ham strcpy, chuoi dest co dang: n%sn" ,  dest ); return ( 0 ); } 

Compile and run the above C program to see the results.

According to Tutorialspoint

Previous lesson: strcoll () function in C

Next lesson: Function strncpy () in C

4 | 1 Vote
« PREV : The strncpy ()...
The strcoll ()... : NEXT »