33,311
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
int Insert(char* dest, char* src, int pos);
char* S1, * S2;
int main(int argc, char* argv[])
{
char s1[80], s2[80];
int n, len;
S1 =s1 ;
S2 =s2 ;
cout << "dest:";
cin >> s1;
cout << "src:";
cin >> s2;
cout << "pos:";
cin >> n;
len = Insert(S1, S2, n); //在下面完成程序编写:调用Insert函数。
cout << "output:" << s1 << ":" << len << endl;
return 0;
}
int Insert(char* dest, char* src, int pos)
{
int i, j;
char temp[80];
temp[0] ='}';
for (i = pos, j = 1; i <= strlen(dest); i++, j++)
temp[j] = dest[i];
dest[pos] = 123;
for (i = 0, j = pos + 1; i <= strlen(src) - 1; i++, j++)
dest[j] = src[i];
dest[j + 1] = '\0';
strcat(dest, temp);
S1 = dest;
return strlen(dest) ;
}