Function Prototypes:
void *memcpy (void *dest,void *src, unsigned int count)
{
ASSERT ((dest!=null) && (src!=null));
if (DEST==SRC)
return SRC;
char* d= (char*) dest;
char* s= (char*) src;
while (count--> 0)
*d++=*s++;
return dest;
}
This is a memcpy source code that generates a temporary pointer inside a function that does not change the original pointer
Parameter description: Dest is the destination string, SRC is the source string, and count is the number of bytes to copy.
function function: Copies the first n bytes of the string src into the dest.
Return Description: SRC and dest memory area can overlap, function returns void* type pointer.
function is the same as memcpy. The difference is that when the memory areas referred to by SRC and dest overlap, the memmove () can still be handled correctly, but the execution efficiency is slightly slower than using memcpy ().
memcpy (), Memmove () and memccpy ()
-------------------------------------------------------
The function of these three functions is to copy a block of memory to another memory block. The difference between the first two functions is that they handle memory area overlap (overlapping) in different ways. The function of the third function is also to replicate memory, but stop copying immediately if a particular value is encountered.
For a library function, you should use the Memmove () function because there is no way to know what is being passed to his memory area. With this function, you can guarantee that there will be no memory block overlap problem. For applications, it is safe to use the memcpy () function because the code "knows" that two blocks of memory do not overlap.
-------------------------------------------------------
#include <string.h>
#include <stdio.h>
int main ()
{
Char s[] = "Zengxiaolong";
Memmove (S, S+4, strlen (s)-4);
S[strlen (s)-4] = ' + ';
printf ("*s =%s\n", s);
return 0;
}
The difference between memcpy and strncpy
strncpy is to copy num characters from SRC to dest, but if it encounters the SRC character end, then the copy is terminated prematurely, the characters that are not copied are not processed, and of course the DEST,SRC address cannot overlap.
memcpy also copies num characters from SRC to dest, but it is a memory copy, whether or not NULL
RELATED Links: http://blog.csdn.net/cq20110310/article/details/7032104
memcpy function Explanation