標準/拡張機能 | C/C++ | 依存項目 |
---|---|---|
ISO C |
両方 |
#include <string.h>
void *memcpy(void * __restrict__dest, const void * __restrict__src, size_t count);
memcpy() 組み込み関数は、src が指すオブジェクトから dest が指すオブジェクトに、count バイトをコピーします。組み込み関数の使用法については、組み込み関数を参照してください。memcpy() の場合、オーバーラップするオブジェクト間でコピーが行われると、ソース文字がオーバーレイされることがあります。memmove() 関数を使用すると、オーバーラップするオブジェクト間のコピーができます。
memcpy() は、dest の値を戻します。
⁄* CELEBM13
This example copies the contents of source to target.
*⁄
#include <string.h>
#include <stdio.h>
#define MAX_LEN 80
char source[ MAX_LEN ] = "This is the source string";
char target[ MAX_LEN ] = "This is the target string";
int main(void)
{
printf( "Before memcpy, target is ¥"%s¥"¥n", target );
memcpy( target, source, sizeof(source));
printf( "After memcpy, target becomes ¥"%s¥"¥n", target );
}
Before memcpy, target is "This is the target string"
After memcpy, target becomes "This is the source string"