memmove wmemmove
將一個緩衝區移至另一個。這些函式更安全版本都可使用; 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
目的地物件。src
來源物件。count
位元組數目 (memmove) 或字元 (wmemmove) 來複製。
傳回值
The value of dest*.*
備註
Copies count bytes (memmove) or characters (wmemmove) from src to dest*.* 如果來源] 區域中的色彩和目的端的某些區域發生重疊,這兩個函式會確保重疊的區域中的原始來源位元組會被複製之前遭到覆寫。
安全性附註請確定目的緩衝區是相同的或大於來源緩衝區。如需詳細資訊,請參閱避免緩衝區滿溢,。
memmove和wmemmove函式將只會取代,如果常數_CRT_SECURE_DEPRECATE_MEMORY之前要包含在陳述式的函式會被取代的順序定義,例如下面範例所示:
#define _CRT_SECURE_DEPRECATE_MEMORY
#include <string.h>
or
#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 );
}
.NET Framework 對等用法
請參閱
參考
strncpy、 _strncpy_l、 wcsncpy、 _wcsncpy_l、 _mbsncpy、 _mbsncpy_l