Export (0) Print
Expand All
div
eof
Expand Minimize
This topic has not yet been rated - Rate this topic

memmove, wmemmove

Moves one buffer to another. More secure versions of these functions are available; see memmove_s, wmemmove_s.

void *memmove(
   void *dest,
   const void *src,
   size_t count 
);
wchar_t *wmemmove(
   wchar_t *dest,
   const wchar_t *src,
   size_t count
);
dest

Destination object.

src

Source object.

count

Number of bytes (memmove) or characters (wmemmove) to copy.

The value of dest.

Copies count bytes (memmove) or characters (wmemmove) from src to dest. If some regions of the source area and the destination overlap, both functions ensure that the original source bytes in the overlapping region are copied before being overwritten.

Security Note   Make sure that the destination buffer is the same size or larger than the source buffer. For more information, see Avoiding Buffer Overruns.

The memmove and wmemmove functions will only be deprecated if the constant _CRT_SECURE_DEPRECATE_MEMORY is defined prior to the inclusion statement in order for the functions to be deprecated, such as in the example below:

#define _CRT_SECURE_DEPRECATE_MEMORY
#include <string.h>
or
#define _CRT_SECURE_DEPRECATE_MEMORY
#include <wchar.h>

Routine

Required header

memmove

<string.h>

wmemmove

<wchar.h>

For additional compatibility information, see Compatibility in the Introduction.

// crt_memcpy.c
// Illustrate overlapping copy: memmove
// always handles it correctly; memcpy may handle
// it correctly.
//

#include <memory.h>
#include <string.h>
#include <stdio.h>

char str1[7] = "aabbcc";

int main( void )
{
   printf( "The string: %s\n", str1 );
   memcpy( str1 + 2, str1, 4 );
   printf( "New string: %s\n", str1 );

   strcpy_s( str1, sizeof(str1), "aabbcc" );   // reset string

   printf( "The string: %s\n", str1 );
   memmove( str1 + 2, str1, 4 );
   printf( "New string: %s\n", str1 );
}
The string: aabbcc New string: aaaabb The string: aabbcc New string: aaaabb
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.