Chinaunix首页 | 论坛 | 博客
  • 博客访问: 544571
  • 博文数量: 252
  • 博客积分: 1068
  • 博客等级: 少尉
  • 技术积分: 1775
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-05 21:33
文章分类

全部博文(252)

文章存档

2013年(21)

2012年(231)

分类:

2012-06-04 14:37:42

原文地址:memcpy函数实现 作者:kevin33643

#include
#include
using namespace std;
 
void *MyMemcpy(void *memDest,const void *memSrc,size_t size)
{
    assert((memDest!=NULL)&&(memSrc!=NULL));
 
    char *tempDest=static_cast(memDest);
    const char *tempSrc=static_cast(memSrc);
   
    if((tempDest>tempSrc)&&(tempDest    {
        for(size_t i=size-1;i!=-1;--i)
            tempDest[i]=tempSrc[i];
    }
    else
    {
        for( size_t i=0;i            tempDest[i]=tempSrc[i];
    }
   
    return memDest;
}
 
int main()
{
    char strSrc[]="12345";
    char strDest[20];
    MyMemcpy(strDest,strSrc,4);
    strDest[4]='\0';//以'\0'结束,勿漏!
    cout<    return 0;
}

 
阅读(325) | 评论(0) | 转发(0) |
0

上一篇:希尔排序

下一篇:Little_endian or Big_endian

给主人留下些什么吧!~~