手撸strcat
作者:
贺谦
,
2021-01-21 00:02:18
,
所有人可见
,
阅读 376
char* my_strcat(char* dest, char* src)
{
char* res = dest;
while (*dest) dest ++;
while (*dest ++ = *src ++);
return res;
}
int main()
{
char firstName[30] = "Jim";
char middleName[30] = "---";
char lastName[30] = "Green";
my_strcat(my_strcat(firstName, middleName), lastName);
printf("%s\n", firstName);
// char* p = firstName;
// char* q = lastName;
// while (*p) p ++;
// while (1)
// {
// *p = *q;
// if (*p == '\0') break;
// p ++;
// q ++;
// }
// printf("%s\n", firstName);
// while (*p ++ = *q ++);
// printf("%s\n", firstName);
return 0;
}