memmovewmemmove

將某個緩衝區移到另一個緩衝區。 這些函式已有更安全的版本可用,請參閱 memmove_swmemmove_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
目的地物件。

src
來源物件。

count
要複製的位元組 (memmove) 或字元 (wmemmove) 數目。

傳回值

dest 的值。

備註

count 個位元組 (memmove) 或字元 (wmemmove) 從 src 複製到 dest。 如果來源與目的地的區域的某些部分重疊,這兩個函式可確保先複製重疊區域中的原始來源位元組,再進行覆寫。

安全性注意事項 請確定目的地緩衝區夠大,足以容納移動的字元數目。 如需詳細資訊,請參閱 Avoiding Buffer Overruns (避免緩衝區滿溢)

只有在 #include 陳述式之前定義 _CRT_SECURE_DEPRECATE_MEMORY 常數時,memmovewmemmove 函式才會被取代,如下列範例所示:

#define _CRT_SECURE_DEPRECATE_MEMORY
#include <string.h>

#define _CRT_SECURE_DEPRECATE_MEMORY
#include <wchar.h>

需求

常式 必要的標頭
memmove <string.h>
wmemmove <wchar.h>

如需相容性詳細資訊,請參閱相容性

範例

// 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

另請參閱

緩衝區操作
_memccpy
memcpy, wmemcpy
strcpywcscpy_mbscpy
strncpy_strncpy_lwcsncpy_wcsncpy_l_mbsncpy_mbsncpy_l