memcpy实现

memcpy

/*
 * =====================================================================================
 *
 *       Filename:  memcp.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2014年02月19日 14时33分41秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Wenxian Ni (Hello World~), niwenxianq@qq.com
 *   Organization:  AMS/ICT
 *
 * =====================================================================================
 */


#include<stdio.h>
void *memcp(void *dest, const void* src, int count)
{
    char *de = (char*)dest;
    char *sr = (char*)src;
    if(de == sr)
        return dest;
    if(sr + count > de && de >src)
        return NULL;
    int i = 0;
    for(i=0;i<count;i++)
    {
        *de = *sr;
        de++;
        sr++;
    }
    return dest;

}

int main()
{
    char a[1000];
    char str[1000];
    char *p = (char*)a;
    while(~scanf("%s",str))
    {
        memcp((void*)a, (void*)str, 100);
        printf("%s
",a);
    }
    return 0;
}

主要看的是两者是否有复合吧

每天早上叫醒你的不是闹钟,而是心中的梦~
原文地址:https://www.cnblogs.com/vintion/p/4116940.html