Many technical tests are written into the string copy function (which database function cannot be used ),
Is there any question about where to take the function test site and when writing it?
It is best to write rigorous routines.
Function declaration:
Char * strcpy (char * strdest, const char * strsrc)
So far, I have concluded that:
1. Test whether strdest and strsrc are not empty.
2. Check whether strdest and strsrc overlap
3. Pay attention to the writing structure
4. Function robustness
In addition, I think if the Data Length of the strsrc buffer exceeds the value of the strdest buffer
But how to check the length of the strdest buffer?
Who else can add?
Strncpy () function: This Program Written by Linus Torvalds, a real cool man.
Char * strncpy (char * DEST, const char * SRC, size_t count)
{
Char * TMP = DEST;
While (count -- & (* DEST ++ = * SRC ++ )! = '\ 0 ')
/* Nothing */;
Return TMP;
}
Someone may say, "No, why not add an end sign to the target string to this:
While (count -- & (* DEST ++ = * SRC ++ )! = '\ 0 ')
/* Nothing */;
* DEST = '\ 0 ';"
As a strncpy function, it just needs to copy the specified length of characters to the target string, without any self-Attention, maybe the function caller does not want this end sign at all. If needed, he will add it himself.
Therefore, a function can only do what you want. This is simplicity. Other functions should understand what the called function can do. This is consistency; unix/Linux itself is a wonderful product with simple consistency principles.