/*
自行编写内存复制函数MyMemcpy()函数
*/
#include <iostream>
using namespace std;
//-------------------------------------
void* MyMemcpy(void* dest,const void* src,size_t count)
{
// if(dest == NULL) return NULL;
// if( src == NULL) return NULL;
// if(count <= 0) return NULL;
char* pdest = static_cast<char*>(dest);
const char* psrc = static_cast<const char*>(src);
if((pdest > psrc)&&(pdest < (psrc + count))) //这一部分没想明白
{
for(size_t i=count-1;i>=0;--i)
{
pdest[i] = psrc[i];
}
pdest[count] = '\0';
}
else
{
for(size_t i=0;i<count;++i)
{
pdest[i] = psrc[i];
}
pdest[count] = '\0';
}
return pdest;
}
int main(int argc, char *argv[])
{
//cout << Myatoi("-12367") << endl;
char str1[] = "-1234";
char* str2;
MyMemcpy(str2,str1,3);
cout << str2 << endl;
return 0;
}