#include
#include
#include
#include
void* mymemcpy(void* _Dst, void const* _Src, unsigned int _Size) {
if (_Dst == NULL || _Src == NULL) {
return NULL;
}
char * ndest = _Dst;
char * src = _Src;
for (int i = 0; i < _Size; i++) {
ndest[i] = src[i];
}
return ndest;
}
void* mynewmemcpy(void* _Dst, void const* _Src, unsigned int _Size) {
if (_Dst == NULL || _Src == NULL) {
return NULL;
}
int i = 0;
for (char *dest = _Dst, *src = _Src;i<_Size; dest++, src++,i++) {
*dest = *src;
}
return _Dst;
}
void main() {
int a[10] = { 1,2,3,4,5,6,7,8,9,0 };
int *p = malloc(sizeof(int) * 10);
mynewmemcpy(p, a, 40);
for (int i = 0; i < 10; i++) {
printf("\n%d", p[i]);
}
char str[1024] = "hello boygod";
char *pstr = malloc(sizeof(char)*(strlen(str) + 1));
char *pnew = mynewmemcpy(pstr, str, strlen(str) + 1);
printf("\n%s", pstr);
printf("\n%s", pnew);
system("pause");
}