C library functions - memmove ()
C standard library - <string.h>
description
C library functionsvoid * memmove (void * str1, const void * str2, size_t n) Copies ncharacters fromstr2tostr1,but overlapping memory block in this regard, memmove () than memcpy () more secure method. If the target area and the source overlap area, then, memmove () to ensure that the source string before it is covered with overlapping byte regions copied to the target area, the contents of the copied source area will be changed. If the target area and the source area does not overlap, and memcpy () function is the same function.
statement
Here is memmove () function's declaration.
void *memmove(void *str1, const void *str2, size_t n)
parameter
- str1 - point to the destination array for storing the copied contents, type cast to void * pointers.
- str2 - pointing to copy the data source, type cast to void * pointers.
- n - thenumber of bytes to be copied.
return value
This function returns a pointer to the destination store str1 pointer.
Examples
The following example demonstrates memmove () function is used.
#include <stdio.h> #include <string.h> int main () { const char dest[] = "oldstring"; const char src[] = "newstring"; printf("Before memmove dest = %s, src = %s\n", dest, src); memmove(dest, src, 9); printf("After memmove dest = %s, src = %s\n", dest, src); return(0); }
Let's compile and run the above program, which will result in the following:
Before memmove dest = oldstring, src = newstring After memmove dest = newstring, src = newstring