问题及代码
/*
完成人:贾如杉
题目描述
将字符串t插入到字符串s中,在位置pos后插入。不得使用字符串操作函数,输出组合成的字符串。
输入
输入两个字符串(t和s)和要插入的位置(pos)
输出
输出组合后的字符串
*/#include <stdio.h>
#include <stdlib.h>
int main()
{
char t[80],s[80],x[80];
int pos,i,j;
gets(t);
gets(s);
scanf("%d",&pos);
for(i=0; i<pos; i++)
{
x[i]=s[i];
}
for(i=0; t[i]!='\0'; i++)
{
x[i+pos]=t[i];
}
j=i+pos;
for(i=pos; s[i]!='\0'; i++,j++)
{
x[j]=s[i];
}
x[j]='\0';
puts(x);
return 0;
}
运行结果
知识点总结
字符串数组的简单运用