memcpy即内存复制,程序如下
void *my_memcopy(void *dst,const void *src,size_t count){ char *pdst = (char*)dst; char *psrc = (char*)src; if(pdst == NULL || psrc == NULL) { return NULL; } if(pdst > psrc && pdst < psrc + count)//防止内存复制重叠,所以从后向前复制 { pdst = pdst + count + 1; psrc = psrc + count + 1; while(count != 0) { *pdst = *psrc; psrc--; pdst--; count--; } } else { size_t i = 0; for(i = 0;i < count;i++) { *pdst = *psrc; psrc++; pdst++; } } return dst;}复制代码