C语言问题,将两个字符串连接起来,要求不用strcat()函数.C语言问题,将两个字符串连接起来,要求不用strcat()函数C莱鸟群:205103464

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/04 11:59:25
C语言问题,将两个字符串连接起来,要求不用strcat()函数.C语言问题,将两个字符串连接起来,要求不用strcat()函数C莱鸟群:205103464

C语言问题,将两个字符串连接起来,要求不用strcat()函数.C语言问题,将两个字符串连接起来,要求不用strcat()函数C莱鸟群:205103464
C语言问题,将两个字符串连接起来,要求不用strcat()函数.
C语言问题,将两个字符串连接起来,要求不用strcat()函数
C莱鸟群:205103464

C语言问题,将两个字符串连接起来,要求不用strcat()函数.C语言问题,将两个字符串连接起来,要求不用strcat()函数C莱鸟群:205103464
#include"stdio.h"
void main()
{
\x09void str_link(char str1[ ],char str2[ ]); //声明str_link函数
\x09char s1[20],s2[20];
\x09printf("任意输入两个字符串,编写函数,实现串的连接.函数原型如下:\n");
\x09printf("void str_link(char str1[ ],char str2[ ]);将串2连接在串1的末尾,形成一个新串\n");
\x09printf("please input s string:\n");
\x09scanf("%s",s1); //输入第一个字符串
\x09printf("please input a string:\n");
\x09scanf("%s",s2); //输入第二个字符串
\x09str_link(s1,s2); //调用str_link函数
\x09printf("%s\n\n",s1);
}
void str_link(char str1[ ],char str2[ ]) //定义str_link函数
{
\x09int i=0,j=0,m=0;
\x09while(str1[i]!='\0') //计算str1的个数
\x09{
\x09\x09m++;
\x09\x09i++;
\x09}
\x09do
\x09{
\x09\x09str1[m]=str2[j]; //将str2复制到str1
\x09\x09m++;
\x09\x09j++;
\x09}while(str2[j]!='\0');
\x09str1[m]='\0';
}