Strcpy与memcpy两函数的经典实现
char *strcpy(char *des, const char *src){
assert((des != NULL) && (src != NULL));
char *add = des;
while ((*des++ = *src++) != ‘\0’) ;
return des;
}
void *memcpy(void *pvTo, const void *pvFrom, size_t size) {
assert((pvTo != NULL) && (pvFrom != NULL)); // 使用断言
byte *pbTo = (byte *) pvTo; // 防止改变pvTo的地址
byte *pbFrom = (byte *) pvFrom; // 防止改变pvFrom的地址
while(size -- > 0
*pbTo ++ = *pbFrom ++ ;
return pvTo;
}
阅读(721) | 评论(0) | 转发(0) |