memcpy ()- 複製位元組

格式

#include <string.h>
void *memcpy(void *dest, const void *src, size_t count);

語言層次

ANSI

安全執行緒

說明

memcpy() 函數會將 srccount 位元組複製到 dest。 如果在重疊的物件之間進行複製,則行為未定義。 memmove() 功能容許在可能重疊的物件之間進行複製。

回覆值

memcpy() 函數會傳回指向 dest的指標。

範例

此範例會將 source 的內容複製到 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 );
}
 
/*********************  Expected output:  ************************
 
Before memcpy, target is "This is the target string"
After memcpy, target becomes "This is the source string"
*/

相關資訊