memmove ()- 複製位元組

格式

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

語言層次

ANSI

安全執行緒

說明

memmove() 函數會將 srccount 位元組複製到 dest。 此功能容許在可能重疊的物件之間進行複製,如同 src 是第一次複製到暫時陣列一樣。

回覆值

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

範例

此範例會將單字 "Shiny" 從位置 target + 2 複製到位置 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 );
}
 
/*********************  Expected output:  ************************
 
Before memmove, target is "a shiny white sphere"
After memmove, target becomes "a shiny shiny sphere"
*/

相關資訊