2022年6月10日星期五

C memcpy

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

n從一個記憶體位址複製n個資料到另一個位址;


  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 memcpy\n");
  10. printf("SayBuf:%s\n",SayBuf);
  11. //目標,來源,長度
  12. memcpy(SayBuf,hello,5);
  13. printf("After memcpy\n");
  14. printf("SayBuf:%s\n",SayBuf);
  15. return 0;
  16. }
  17.  

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

沒有留言:

發佈留言

打賞按讚