<>strcpy Overlay copy

*
The copied string must be in ’\0’ end .

*
The target space should be large enough , At least you should be able to put down the copy .

*
The value of the target space can be modified , For example, the string in the constant area , Cannot modify , You can't use it .

*
Will be copied in the string ’\0’ Copy to target space .

*
Function implementation .
Method 1
char* my_strcpy(char* dst, const char* src) { const ret = dst; while (*src) {
*dst = *src; dst++; src++; } *dst = '\0'; return ret; }
   ret Record the first address of the string , Set the return value of the function to a char*, This is to call functions like my_strcpy(str1,
my_strcpy(str1, p1)); Nesting like this , because strcpy Copy is copy ’\0’ Of , So in the end , We need it *dst The last point is changed to ’\0’.
Method 2
char* my_strcpy(char* dst, const char* src) { const ret = dst;
// Assignment first , Judge again , As long as it's not \0, The code continues while (*dst++ = *src++); return ret; }
   Method 2 is simplified as compared with method 1 , Using front end ++ The way , Preposition ++ Priority of is higher than *, So it doesn't cycle once , Move the pointer backward , And then src The value of is assigned to dst.

Technology