qfedu-c-level/day10/homework/h14.c

28 lines
659 B
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 设计函数,给定两个字符串指针,实现将第二字符串的内容拼接到第一个字符串中,并返回第一个字符串指针。
#include <stdio.h>
char *concat(char *dest, char *src)
{
while (*dest) // 找到 dest 的末尾
{
dest++;
}
while (*src) // 将 src 的内容复制到 dest 的末尾
{
*dest = *src;
dest++;
src++;
}
*dest = '\0'; // 最后补上字符串结束符
return dest; // 返回 dest 的首地址
}
int main()
{
char m[128] = "";
concat(m, "disen");
concat(m, ", 666");
printf("%s\n", m); // 输出结果disen, 666
return 0;
}