The basic contents of the strcpy function:
Prototype declaration: extern Char *strcpy (char* dest, const char *SRC);
header files: #include <string.h> and #include <stdio.h>function: Copies a string that starts from the SRC address and contains a null terminator to Dest.address SpaceDescription: The memory areas referred to by SRC and dest cannot overlap and dest must have sufficient space to accommodate the SRC string. returns a pointer to the DestPointers. knowing the contents of the function, we can then simply implement this function:
#include <stdio.h> #include <assert.h>char * my_strcpy (char *str1,char const *STR2) {char *tmp=str1;assert ( STR1); ASSERT (STR2); while (*str2!= ') {*str1++ = *str2++;} return TMP;} int main () {char p[10]= "abc"; char *q= "DEFG";p rintf ("%s\n", my_strcpy (P,q)); return 0;}
The results of the operation are as follows:
Implementation of "C language" strcpy function