memcpy

 

memcpy
  原型:extern void *memcpy(void *dest, void *src, unsigned int count);
  用法:#include <string.h>
  功能:由src所指內存區域複製count個字節到dest所指內存區域。
  說明:srcdest所指內存區域不能重疊,函數返回指向dest的指針。
  注意:與strcpy相比,memcpy並不是遇到'/0'就結束,而是一定會拷貝完n個字節。
  舉例:
  // memcpy.c
  #include <stdio.h>
  #include <string.h>
  int main(int argc, char* argv[])
  {
  char *s="Golden Global View";
  char d[20];
  clrscr();
  memcpy(d,s,strlen(s));
  d[strlen(s)]='/0';
  printf("%s",d);
  getchar();
  return 0;
  }
  截取view
  #include <string.h>
  int main(int argc, char* argv[])
  {
  char *s="Golden Global View";
  char d[20];
  memcpy(d,s+14,4);
  //memcpy(d,s+14*sizeof(char),4*sizeof(char));也可
  d[4]='/0';
  printf("%s",d);
  getchar();
  return 0;
  }
  輸出結果:
  View
  初始化數組
  char msg[10];
  memcpy(msg,0,sizeof(msg));
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章