题目:
使用指针连接两个字符串
将两个字符串连接,放到另外一个字符串数组中。
源代码:
#include <stdio.h>
#include <string.h>
void connect_char(const char * x,const char * y,char * z);
int main()
{
char o_char[20],t_char[20],ch_o_and_t[40];
printf("请输入第一个字符串: ");
fgets(o_char,20,stdin);
printf("请输入第二个字符串: ");
fgets(t_char,20,stdin);
connect_char(o_char,t_char,ch_o_and_t);
printf("两个字符串连接后的字符串为: %s",ch_o_and_t);
return 0;
}
void connect_char(const char * x,const char * y,char * z)
{
while(*x != '\n') *z++ = *x++;
while(*y != '\n') *z++ = *y++;
*z = '\0';
}
演示效果:
如果朋友你感觉文章的内容对你有帮助,可以点赞,关注文章和专栏以及关注我哈,嘿嘿嘿我会定期更新文章的,谢谢朋友你的支持哈