memcpy函数实现(c语言)

memcpy函数实现(c语言)

second60  20180530

#include <stdio.h>
#include <assert.h>
void *memcpy_new(void *to, void *from, size_t size)
{
    char *tempFrom = NULL;
    char *tempTo   = NULL;
    assert( to && from );
    /*先转型为字符指针,字符为一个字节*/
    tempFrom = (char*)from;
    tempTo   = (char*)to;
    while(size-- > 0)
    {
        *tempTo++ = *tempFrom++;
    }
    return to;
}
int main()
{
    char strSrc[] = "hello world";
    char strDest[20];


    memcpy_new(strDest, strSrc, 8);
    strDest[8] = '\0';
    printf("str=%s\n",strDest);
    getchar();
    return 0;
}


猜你喜欢

转载自blog.csdn.net/second60/article/details/80504377
今日推荐