I need to use these functions in my work today. I have a little understanding of the differences between these functions and write a short article:
1. char * strcpy (char * DEST, char * SRC); this function copies the string ending with '\ 0' indicated by Src to the array indicated by DeST. The memory areas specified by Src and DEST cannot overlap and DEST must have enough space to hold SRC strings. When the SRC string length> DEST String Length,ProgramThe entire SRC string will still be copied to the Dest region, but the Dest array has exceeded.
2. char * strncpy (char * DEST, char * SRC, size_t, N ); copy up to n characters in the SRC string to the Dest character array (it does not stop copying when it encounters null like strcpy, but starts copying only when it has enough n characters ), returns the pointer to DeST.
3. Void * memcpy (void * DEST, const void * SRC, size_t N ); data of N consecutive bytes directed by Src to the starting address is copied to the space where the starting address is directed by DeST .. The source and DESTIN memory regions cannot overlap. The function returns a pointer to Destin. Compared with strcpy, memcpy does not end when '\ 0' is encountered, but will definitely copy n Bytes. If the target array DESTIN already has data, after memcpy () is executed, the original data will be overwritten (N at most ). If you want to append data, you need to add the target array address to the address where you want to append the data after executing memcpy.