It is known that the strcpy function prototype is char * strcpy (char * strdest, const char * strsrc), where strdest is the destination string and strsrc is the source string. Do not call the string library function of C ++/C. Compile the strcpy function.
1 # include <cassert> 2 3 char * strcpy (char * strdest, const char * strsrc) 4 {5 assert (strdest & strsrc ); // 2 points 6 char * CP = strdest; // 2 points 7 while (* CP ++ = * strsrc ++) // 2 points 8; 9 return strdest; // 2 points 10}
A: To implement a chained expression. // 2 points
For example, int length = strlen (strcpy (strdest, "Hello World "));
In addition, the strlen function is as follows:
1 int strlen (const char * Str) 2 {3 assert (STR); 4 int Len = 0; 5 while (* STR ++) 6 {7 Len ++; 8} 9 return Len; 10}
Strcat function implementation:
1 char * strcat (char * strdest, const char * strsrc) 2 {3 assert (strdest & strsrc); 4 char * Pd = strdest; 5 while (* PD ++); 6 While (* PD ++ = * strsrc ++); 7 return strdest; 8}