1 #include <stdio.h>
2 #include <string.h>
3 int main(void)
4 {
5 char a[128],b[128],temp[128];
6 int i,j,g,m=0,index,n,k;
7 printf("get string a:\n");
8 gets(a);
9 printf("get string b:\n");
10 gets(b);
11 index=0;
12 k=strlen(a);
13 n=strlen(b);
14 for(i=1;a[i]!='\0';i++)
15 {
16 if(a[index]<a[i])
17 index=i;
18 else
19 continue;
20 }
21 strcpy(temp,a);
22 for(i=0;i<=index;i++)
23 temp[i]=a[i];
24 for(j=0;j<n+1;j++)
25 temp[j+i]=b[j];
26 i=index+n+1;
27 for(j=index+1;a[j]!='\0';j++)
28 {
29 temp[i]=a[j],i++;
30 }
31 temp[i]='\0';
32 printf("the result is:\n");
33 puts(temp);
34 }
方法2:
1 #include <stdio.h>
2 #include <string.h>
3 int main(void)
4 {
5 char a[128],b[128],temp[128];
6 int i,j,g,m=0,index,n,k;
7 printf("get string a:\n");
8 gets(a);
9 printf("get string b:\n");
10 gets(b);
11 index=0;
12 k=strlen(a);
13 n=strlen(b);
14 for(i=1;a[i]!='\0';i++)
15 {
16 if(a[index]<a[i])
17 index=i;
18 else
19 continue;
20 }
21 strcpy(temp,a);
22 strcpy(&temp[index+1],b);
23 strcpy(&temp[index+n+1],&a[index+1]);
24 if(strlen(temp)<=126)
25 strcpy(a,temp);
26 else
27 strcpy(a,temp);
28 a[127]='\0';
29 printf("the result is:\n");
30 puts(a);
31 }