qfedu-c-level/day11/d12.c

27 lines
500 B
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *str_cat(char *dest, char *src)
{
int insert_pos = 0;
while (dest[insert_pos])
insert_pos++;
// 在 dest 的第一个 '\0' 处插入 src 内容
for (int i = 0; i <= strlen(src); i++)
// for (int i = 0; *(src + i); i++)
{
dest[insert_pos++] = *(src + i);
}
return dest;
}
int main()
{
char p[100] = "good, 1\023";
str_cat(p, "小李子");
printf("%s\n", p);
return 0;
}