strcpy
void my_strcpy(char *pdest, char *psrc)
{
while (*psrc != '\0')
{
*(pdest++) = *(psrc++);
}
*pdest = *psrc;
}
int main()
{
char arr[20] = { 0 };
my_strcpy(arr, "hello world");
printf("%s\n", arr);
system("pause");
return 0;
}
char* my_strcpy(char *pdest,const char *psrc)
{
char *ret = pdest;
assert(pdest && psrc);
while (*pdest++ = *psrc++)
{
;
}
return ret;
}
int main()
{
char arr[20] = "aaaaaaaaaaaaaaaaa";
//char *p = "hello world.";
//strcpy(arr, p);
//strcpy(arr, "hello world.");
//my_strcpy(arr, p);
//printf("%s\n", arr);
printf("%d\n", strlen(my_strcpy(arr, "hello world")));
system("pause");
return 0;
}
结果为 12