2022年6月10日星期五

C memmove

void    *memmove(void *dest, const void *src, size_t n);

n從一個記憶體位址複製n個資料到另一個位址,有點類似memcpy,但又有點不同

不同的地方在stack overflow有說明

memmove 可允許目標與來源位址相同

  1. /*This file use to record string.h library use */
  2. #include <string.h>
  3. #include <stdio.h>
  4. char SayBuf[10]="";//char buffer
  5. char *hello="Hello\n";//show chars
  6.  
  7. int main()
  8. {
  9. printf("Before memmove\n");
  10. printf("SayBuf:%s\n",SayBuf);
  11. //目標,來源,長度
  12. memmove(HelloBuf,HelloBuf,5);
  13. printf("After memmove\n");
  14. printf("SayBuf:%s\n",SayBuf);
  15. printf("HelloBuf:%s\n",HelloBuf);
  16. return 0;
  17. }
  18.  




可以看到在還沒有執行memmove之前,印出來的資料是空的,直到執行memmove之後才有資料

沒有留言:

發佈留言

打賞按讚