其他分享
首页 > 其他分享> > C memmove函数代码实现

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

 

标签:count,src,函数,memmove,dest,代码,char,--,void
来源: https://www.cnblogs.com/feizianquan/p/14651403.html