The idea is to give the possibility to chain the functions. I.e. to pass one function result as a parameter to another one.
sstrcpy ( destination2, sstrcpy ( destination1, source ));
As for the proposed sstrcpy2
- it will only return a single, the last character of the copied string, which is apparently
in your implementation, which is rather useless in most cases.
Update:
Note that the implementation sstrcpy
is incorrect as is, it will return the value of destination
, which was already moved to the end of the string, and not the pointer to the beginning of it. Alternatively I would suggest saving the original pointer and increment it's copy instead:
char *sstrcpy ( char *destination, const char *source ){ //return a pointer to destination
char *dst = destination;
while ((*dst++ = *source++));
*dst='';
return destination;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…