参考:https://www.cnblogs.com/huanzxj/p/3522595.html
#include <iostream>
void *stringcpy(char *str1, const char *str2)
{
if (str1 == NULL || str2 == NULL)
{
return NULL;
}
char *temp = str1;
while (*str2!='\0')
{
*temp++ = *str2++;
}
*temp = '\0';
return str1;
}
void *memorycpy(void *memto, const void *memfrom, size_t size)
{
if (memto == NULL || memfrom == NULL)
{
return NULL;
}
char *temp = (char*)memto;
char *from = (char*)memfrom;
for (int i = 0; i < size; i++)
{
*temp++ = *from++;
}
return memto;
}
int main()
{
char str1[10] = "lanmao";
const char *str2 = "hi";
char*s4 = new char[10];
memorycpy(s4, str1, 7);//str1拷贝到s4
char *s3=(char*)stringcpy(str1, str2);
printf("%s\n",s3);
printf("%s\n", s4);
std::cout << "Hello World!\n";
return 0;
}