void *memcpy(void* memTo, const void* memFrom, size_t size)
{
assert((memTo != NULL)&&(memFrom != NULL)); //memTo和memFrom必须有效
char* tempFrom = (char*)memFrom; //保存memFrom首地址
char* tempTo = (char *)memTo;//保存memTo首地址
while (size-- > 0)
{
*tempTo++ = *tempFrom++;
}
return memTo;
}
int main()
{
char strSrc[] = "Hello world!";
char strDest[20];
memcpy(strDest,strSrc,sizeof(strSrc)/sizeof(*strSrc)+1);
printf("strDest:%s\n", strDest);
system("pause");
return 0;
}
lpl312905509
发布了43 篇原创文章 · 获赞 1 · 访问量 2281
私信
关注