面试题----实现memcpy

#include <stdio.h>



void *memcpy(void *memTo,const void *memFrom,size_t size)
{
    if(memTo == NULL || memFrom == NULL)
        return NULL;
    char *p = (char *)memTo;
    char *q = (char *)memFrom;
    while(size > 0)
    {
        *p = *q;
        p++;
        q++;
        size--;
    }
    return memTo;
}
int main()
{
    char strSrc[] = "Hello World!";
    char strDest[20];
    memcpy(strDest,strSrc,4);
    strDest[4] = '\0';
    printf("赋值结果为:%s\n",strDest);
    return 0;
}

 

posted @ 2017-11-13 21:31  青儿哥哥  阅读(610)  评论(0编辑  收藏  举报