memcpy(转)

memcpy

 原型:extern void *memcpy(void *dest, void *src, unsigned int count);

 用法:#include <string.h>

 功能:由src所指内存区域复制count个字节到dest所指内存区域。

 说明:src和dest所指内存区域不能重叠,函数返回指向dest的指针。

 举例:

 // memcpy.c

 view plaincopy to clipboardprint?

 ·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150

 #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

 view plaincopy to clipboardprint?

 ·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150

 #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[5]='\0';

 printf("%s",d);

 getchar();

 return 0;

 }

 输出结果:

 View

 初始化数组

 char msg[10];

 memcpy(msg,0,sizeof(msg));

 

 

转自:http://doc.chinaunix.net/dotnet/200907/165174.shtml

 

posted @ 2010-08-02 17:12  新绿  阅读(263)  评论(0编辑  收藏  举报