void * Mymemcpy(void * dest ,const void *src ,size_t count) { void *temp = dest; if (dest< src) { while (count--) { *(char *)dest = *(char *)src; ++(char *)src; ++(char *)dest; } } else if(dest > src) { (char *)dest += count; (char *)src += count; count++; while (count--) { *(char *)dest = *(char *)src; --(char *)src; --(char *)dest; } } return temp; }
或者简便写
void * Mymemmove(void * dest ,const void *src ,size_t count) { void *temp = dest; if (dest< src) { while (count--) { *(char *)dest = *(char *)src; ++(char *)src; ++(char *)dest; } } else { while (count--) { *((char *)dest+ count) = *((char *)src + count); } } return temp; }