题目描述
实现两个字符串(不包含空格)的连接。
编写一个字符串连接函数,函数声明为:
void scat(char *p1,char *p2);
作用是将指针变量p2指向的字符串连接到p1指向的字符串的末尾。
输入格式
共2行,每行1个字符串。
输出格式
共1行,1个字符串(第一行字符串连接到第二行字符串,然后打印输出)。
输入输出样例
输入 #1复制
abc def
输出 #1复制
defabc
说明/提示
#include<iostream>;
using namespace std;
void scat(char *p1,char *p2){
//将程序补充完整
}
int main()
{
char s1[50],s2[110];
cin>>s1;
cin>>s2;
scat( s1, s2);
cout<<s2;
return 0;
}
/*实现两个字符串的连接。
例如:输入dfdfqe和12345时,则输出dfdfqe12345*/
#include <stdio.h>
#include <string.h>
void scat (char s1[], char s2[]);
int main() {
char s1[80], s2[80];
gets(s1);
gets(s2);
scat(s1, s2);
puts(s1);
return 0;
}
void scat (char s1[], char s2[]) {
int i = 0, j = 0;
while (s1[i])
i++;
while (s2[j]) {
i++;
j++;
}
s1[i] = '\0';
}