c函数memcpy实现
作者:互联网
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
私信
关注
标签:memFrom,函数,strSrc,实现,char,memTo,memcpy,strDest,size 来源: https://blog.csdn.net/lpl312905509/article/details/104078475