第十五周-将字符串插入到另一个字符串的指定位置(串)
#include#includeint main(){char t[80],s[80];int i,n1,n2,pos;gets(t);gets(s);scanf("%d",&pos);n1=strlen(t);n2=strlen(s);for(i=n2-1;i>=pos;--i){
·
#include <stdio.h>
#include <string.h>
int main()
{
char t[80],s[80];
int i,n1,n2,pos;
gets(t);
gets(s);
scanf("%d",&pos);
n1=strlen(t);
n2=strlen(s);
for(i=n2-1;i>=pos;--i)
{
s[i+n1]=s[i];
}
for(i=0;i<n1;++i)
{
s[pos++]=t[i];
}
for(i=0;i<n1+n2;++i)
printf("%c",s[i]);
//puts(s)
//因为移动字符会破坏原有自动添加的/0,所以只好用for循环输出指定数目的元素
//后来一想,把'\0'也跟着移动不就完了?但是懒得修改了。。
return 0;
}
更多推荐

所有评论(0)