memcpy() - バッファーのコピー

標準

標準/拡張機能 C/C++ 依存項目

ISO C
XPG4
XPG4.2
C99
Single UNIX Specification、バージョン 3

両方  

形式

#include <string.h>

void *memcpy(void * __restrict__dest, const void * __restrict__src, size_t count);

機能説明

memcpy() 組み込み関数は、src が指すオブジェクトから dest が指すオブジェクトに、count バイトをコピーします。組み込み関数の使用法については、組み込み関数を参照してください。memcpy() の場合、オーバーラップするオブジェクト間でコピーが行われると、ソース文字がオーバーレイされることがあります。memmove() 関数を使用すると、オーバーラップするオブジェクト間のコピーができます。

戻り値

memcpy() は、dest の値を戻します。

CELEBM13
⁄* 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"

関連情報