memcpy用法

memcpy原型:extern void *memcpy(void *dest, void *src, unsigned int count);   用法:#include <string.h>   
功能:由src所指内存区域复制count个字节到dest所指内存区域。   
说明:src和dest所指内存区域不能重叠,函数返回指向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));
posted @ 2010-11-20 02:32  瓜蛋  阅读(889)  评论(0编辑  收藏  举报