C memmove函数代码实现
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; }
从此山高路远,纵马扬鞭。愿往后旅途,三冬暖,春不寒,天黑有灯,下雨有伞。此生尽兴,不负勇往。