strcpy () This function should be used by everyone, today, we will implement this function
int main (void)
{
char arr1[20];
Char arr2[] = "Hello world!";
char *arr2 = NULL;
my_strcpy (arr1, arr2);
printf ("%s", arr1);
System ("pause");
return 0;
}
As above, first set the overall framework, and then start to write the my_strcpy function
char * my_strcpy (char * dest, const char * src) //const make SRC Unable to do the left value to prevent while Dest and SRC write anti-
{
char *ch = dest;
assert (dest!= NULL); Assertion helps debug
assert (src!= NULL);
while (*dest++ = *src++) The//while is the simplest
;
return dest; Chained access printf ("%s", my_strcpy (dest, SRC));
As above, the comments are very detailed. It is worth mentioning that the assert (), which is called an assertion, means that when its condition is false, the program crashes and then gives a hint, which can help us debug the program well. To use this assertion, we want to include the header file on it: #include <assert.h>.