Why is the return value of STRCPY is char *?

xiaoxiao2021-03-06  108

When I face this topic in the written test, I didn't hesitate to write this answer:

If the length of STRDEST is less than strsrc, strDest is removed, and then the New is the same size with the STRSRC.

Since I know that the test is coming from Lin Rui's "High Quality C Programming Guide", I went back, I got out the relevant information, the result is expected, the following is from the original text:

[Recommendation 6-2-1] Sometimes the function does not need to return value, but in order to increase flexibility, such as support chain expression, you can add a return value. For example, the prototype of the string copy function STRCPY: char * strdest, const char * strsrc); the STRCPY function copies the strsrc to the output parameter strDest, and the return value of the function is STRDEST. Do not have more this, you can get the following flexibility: CHAR STR [20]; Int Length = Strlen (STRCPY (STR, "Hello World");

I am not very advocating to find Microsoft's source code:

/ **** Char * STRCPY (DST, SRC) - Copy One String over another ** purpose: * Copies the string src inTo the Spot specified by * DEST; assumes enough room. ** Entry: * char * dst - string Over which "src" is to be copied * const char * src - String to be copied over "dst" ** EXIT: * The address of "dst" ** exceptions: ************ *********************************************************** ***************** /

Char * __cdecl struct (char * dst, const char * src) {char * cp = dst;

While (* CP = * SRC ); / * Copy SRC over DST * /

Return (DST);

It seems that the fact is that Lin Rui said, only for easy use.

转载请注明原文地址:https://www.9cbs.com/read-124624.html

New Post(0)