从键盘输入两个字符串,将第二个字符串连接在第一个字符串的末尾,然后输出连接后的字符串。要求不能使用strcat函数。
输入格式:
输入只有一行,为两个字符串,中间用空格隔开。每个字符串的长度都不超过100。
输出格式:
输出只有一行,为连接后的字符串。
输入样例:
hello world
输出样例:
helloworld
代码:
#include<stdio.h>
#include<string.h>
int main(){
char ch1[110],ch2[110];
int i,j,n,m;
scanf("%s",ch1);
scanf("%s",ch2);
n=strlen(ch1);//得到字符串的长度
m=strlen(ch2);
for(i=n,j=0;j<=m;i++,j++){
ch1[i]=ch2[j];
}
printf("%s",ch1);
return 0;
}
使用的字符串处理函数:
strlen
#include <string.h>
size_t strlen(const char *str);
返回字符串str的长度,’\0’不算在内。