memcpy与strcpy实现
时间:2010-03-05 来源:doujiao
memcpy与strcpy实现
void* memcpy(void* pvTo, const void* pvForm, size_t size)
{
assert((pvTo!= NULL) && (pvFrom!= NULL));//使用断言防止传递空地址
unsigned char* pbTo = (unsigned char*)pvTo;//防止改变pvTo的地址
unsigned char* pbFrom = (unsigned char*)pvFrom;//防止改变pvFrom的地址
while(size-- > 0)
{
*pbTo++ = *pbFrom++;
}
return pvTo;
}
char* strcpy(char* pDest, const char* pSrc)
{
assert((pDest != NULL) && (pSrc != NULL));
char *pTmp = pDest;
while ((*pDest++ = *pSrc++) != '\0')
;
return pTmp;
}
相关阅读 更多 +