The prototype of the known strcpy function is a char *strcpy (char *strdest, const char *STRSRC);
Where strdest is the destination string, Strsrc is the source string.
(1) Do not call the C++/C string library function, write the function
strcpy Char *strcpy (char *strdest, const char *STRSRC);
{
ASSERT ((strdest!=null) && (strsrc!=null)); 2 min
char *address = strdest; 2 min
while ((*strdest++ = * strsrc++)! = ' + ')//2 min
NULL;
return address; 2 min
}
(2) strcpy can copy the contents of STRSRC to strdest, why do you want the return value of char * type?
Answer: In order to implement the chain expression. 2 min
For example int length = strlen (strcpy (strdest, "Hello World"));
--------------------------------------------------------------------------------------------------------------- -----------------
See the word: Chain expression, have not heard before, so went to Baidu a bit, found that some people explain the figure is clear:
--------------------------------------------------------------------------------------------------------------- -----------------http://topic.csdn.net/t/20061123/21/5180993.html 1,
is convenient, otherwise it will be written:
Char strdest[12];
strcpy (strdest, "Hello World");
int length = strlen (strdest);
What chain is a series of written down meaning ...
--------------------------------------------------------------------------------------------------------------- -----------------
In fact, plainly, is if the above string copy function strcopy return value is void, then, the above sentence:
int length = strlen (strcpy (strdest, "Hello World"));
It is like the answer of the above, written several sentences:
Char strdest[12];
strcpy (strdest, "Hello World");
int length = strlen (strdest);
This method of directly returning char * is designed for the convenience of later function callers. You don't have to bother with this. Using the above methods, you can directly use the copy of the Dest string. This is a convenient way to do this, it looks like chain-chained, so called chained expression
That's all. hehe.
About chaining expressions
The prototype of the known strcpy function is a char *strcpy (char *strdest, const char *STRSRC);
Where strdest is the destination string, Strsrc is the source string.
(1) Do not call the C++/C string library function, write the function
strcpy Char *strcpy (char *strdest, const char *STRSRC);
{
ASSERT ((strdest!=null) && (strsrc!=null)); 2 min
char *address = strdest; 2 min
while ((*strdest++ = * strsrc++)! = ' + ')//2 min
NULL;
return address; 2 min
}
(2) strcpy can copy the contents of STRSRC to strdest, why do you want the return value of char * type?
Answer: In order to implement the chain expression. 2 min
For example int length = strlen (strcpy (strdest, "Hello World"));
--------------------------------------------------------------------------------------------------------------- -----------------
See the word: Chain expression, have not heard before, so went to Baidu a bit, found that some people explain the figure is clear:
--------------------------------------------------------------------------------------------------------------- -----------------http://topic.csdn.net/t/20061123/21/5180993.html 1,
is convenient, otherwise it will be written:
Char strdest[12];
strcpy (strdest, "Hello World");
int length = strlen (strdest);
What chain is a series of written down meaning ...
--------------------------------------------------------------------------------------------------------------- -----------------
In fact, plainly, is if the above string copy function strcopy return value is void, then, the above sentence:
int length = strlen (strcpy (strdest, "Hello World"));
It is like the answer of the above, written several sentences:
Char strdest[12];
strcpy (strdest, "Hello World");
int length = strlen (strdest);
This method of directly returning char * is designed for the convenience of later function callers. You don't have to bother with this. Using the above methods, you can directly use the copy of the Dest string. This is a convenient way to do this, it looks like chain-chained, so called chained expression
That's all.
Implementation of strcpy function