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;
}

 

上一篇:Java-note-字符串转换为基本值


下一篇:如何搞定Critical Thinking写作?