C language: Compile strcpy Functions
When interviewing programmers, the interviewers of many companies ask the candidates to write the library function strcpy (), which is called implementation. Many people think that this question is very simple, although such a small function can be examined from three aspects: (1) programming style (2) Error Processing (3) algorithm complexity analysis (used to improve performance) the best syntax is as follows: the Code is as follows:
# Include <stdio. h> # include <stdlib. h> # include <assert. h> // chain access char * my_strcpy (char * dest, const char * src) {// Add the source string to const, indicating that it is the input parameter assert (src! = NULL & dest! = NULL); // Add non-0 asserted char * ret = dest to the source address and target address; while (* dest ++ = * src ++); return ret; // reference the return address to facilitate chained Operations !!} Int main () {char * p = "bit-tech"; char arr [20]; // strcpy (arr, p); printf ("% d \ n ", strlen (my_strcpy (arr, p); system ("pause"); return 0 ;}
Write the strlen function.