copy函数的技术推演:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void _strcpy(char* from, char* to)
{
if (from == NULL || to == NULL)
{
printf("parameter is null error!\n");
return;
}
while (*to++ = *from++)
{
;
}
}
int main1()
{
char from[] = "abcdefg";
char to[64] = { 0 };
_strcpy(from, to);
printf("to=%s\n", to);
system("pause");
return 0;
}
int main()
{
char* from = "123456789";
char* to = NULL;
to = (char*)malloc(16);
_strcpy(from, to);
printf("to=%s\n", to);
free(to);
system("pause");
return 0;
}