memmove() - バッファーの移動
標準
| 標準/拡張機能 | C/C++ | 依存項目 |
|---|---|---|
ISO C
XPG4 XPG4.2 C99 Single UNIX Specification、バージョン 3 |
両方 |
形式
#include <string.h>
void *memmove(void *dest, const void *src, size_t count);機能説明
src が指すオブジェクトから dest が 指すオブジェクトに count バイトをコピーします。memmove() 関数を使用すると、オーバーラップの可能性があるオブジェクト間のコピーを、src により指定されるオブジェクトの count バイトが一時配列にコピーしてから、dest で指定されるオブジェクトにコピーされるようにすることができます。
戻り値
memmove() は、dest の値を戻します。
例
CELEBM14
/* CELEBM14
This example copies the word shiny from position target + 2
to position target + 8.
*/
#include <string.h>
#include <stdio.h>
#define SIZE 21
char target[SIZE] = "a shiny white sphere";
int main( void )
{
char * p = target + 8; /* p points at the starting character
of the word we want to replace */
char * source = target + 2; /* start of "shiny" */
printf( "Before memmove, target is ¥"%s¥"¥n", target );
memmove( p, source, 5 );
printf( "After memmove, target becomes ¥"%s¥"¥n", target );
}
出力:
Before memmove, target is "a shiny white sphere"
After memmove, target becomes "a shiny shiny sphere"