您的位置:首页 > 其它

九度oj 题目1490:字符串链接

2017-03-01 11:19 323 查看
题目1490:字符串链接

时间限制:1秒

内存限制:128兆

特殊判题:

提交:2610

解决:1321

题目描述:
不用strcat函数,自己编写一个字符串链接函数MyStrcat(chardstStr[],charsrcStr[])

输入:
两个字符串,字符串由小写字母组成。

输出:
链接后的字符串

样例输入:
helloworld
goodmorning

样例输出:
helloworld
goodmorning


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char*MyStrcat(chardstStr[],charsrcStr[]){
inti,len1=strlen(dstStr);
intlen2=strlen(srcStr);
char*str=(char*)malloc(sizeof(char)*(len1+len2+1));
char*tmp=str;
for(i=0;dstStr[i]!='\0';i++){
*(tmp++)=dstStr[i];
}
for(i=0;srcStr[i]!='\0';i++){
*(tmp++)=srcStr[i];
}
*tmp='\0';
returnstr;
}

intmain(){
chars1[256],s2[256];
while(scanf("%s%s",s1,s2)!=EOF){
printf("%s\n",MyStrcat(s1,s2));
}
return0;
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: