A topic programmed to implement a string copy function strcpy (), many people often write the following code quickly.
void strcpy (char *strdest,char *strsrc) { while ((*strdest++ = * strsrc++)! = ');//assignment of data in a string array, knowing the end of the string}
Actually take a closer look at this implementation process is not perfect, strictly speaking very not rigorous, we can improve.
char * strcpy (char *strdest, const char *STRSRC)//Adds the source string const, indicating that read-only is the input parameter { assert (strdest! = NULL) && (STRSR c! = NULL));//to the source address and destination address plus a non-0 assertion, judging validity char *address = strdest; while ((*strdest++ = *strsrc++)! = 0 ');//Copy the return address one by one ;}
This procedure looks more perfect, the interviewer will be very satisfied.
Write implement string copy function strcpy () full version