描述
C庫函數void *memmove(void *str1, const void *str2, size_t n)副本n人物來自str2至str1,但對於重疊的內存塊,memmove() 是比 memcpy() 更安全的方法。
聲明
以下是 memmove() 函數的聲明。
void *memmove(void *str1, const void *str2, size_t n)
參數
str1- 這是指向要複製內容的目標數組的指針,type-casted 指向 void* 類型的指針。
str2- 這是一個指向要複製的數據源的指針,type-casted 指向一個 void* 類型的指針。
n- 這是要複製的字節數。
返回值
此函數返回一個指向目標的指針,即 str1。
示例
下麵的例子展示了 memmove() 函數的用法。
#include <stdio.h>
#include <string.h>
int main () {
char dest[] = "oldstring";
const char src[] = "newstring";
printf("Before memmove dest = %s, src = %s\n", dest, src);
memmove(dest, src, 9);
printf("After memmove dest = %s, src = %s\n", dest, src);
return(0);
}
讓我們編譯並運行上麵的程序,將產生以下結果 -
Before memmove dest = oldstring, src = newstring After memmove dest = newstring, src = newstring
相關用法
- C語言 memchr()用法及代碼示例
- C語言 memset()用法及代碼示例
- C語言 memcpy()用法及代碼示例
- C語言 memcmp()用法及代碼示例
- C語言 moveto()用法及代碼示例
- C語言 mbtowc()用法及代碼示例
- C語言 modf()用法及代碼示例
- C語言 moverel()用法及代碼示例
- C語言 mktime()用法及代碼示例
- C語言 malloc()用法及代碼示例
- C語言 mblen()用法及代碼示例
- C語言 mbstowcs()用法及代碼示例
- C語言 宏 assert()用法及代碼示例
- C語言 vprintf()用法及代碼示例
- C語言 宏 va_start()用法及代碼示例
- C語言 setlocale()用法及代碼示例
- C語言 fread()用法及代碼示例
- C語言 sinh()用法及代碼示例
- C語言 宏 offsetof()用法及代碼示例
- C語言 feof()用法及代碼示例
注:本文由純淨天空篩選整理自 C library function - memmove()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。