Function name : strcpy
Header file : <string.h>
Function prototype: char *strcpy(char *destin, const char *source);
Function: Copy a string to another string array
Parameters : char *destin is the copied target string array
const char *source is the copied source string array
Return value : Returns a pointer to the target string array
Note : Destin must be large enough to accommodate the source, otherwise an overflow error will occur. This function does not generate a new string, but modifies the original string. Therefore, destin can only be a character array, not a string pointed to by a string pointer, because the string pointer points to a string constant, and the constant cannot be modified.
Program example : Copy a string pointer to a string array and output the copied target string
#include<string.h>#include<stdio.h>intmain(void){charstring[10];char*str1=www.dotcpp.com;strcpy(string,str1);printf(%sn,string) ;return0;}
Running results:
www.dotcpp.com