1个回答
展开全部
#include <stdio.h>
#include <string.h>
void insert(char s1[ ],char s2[ ],int pos)
{
if(pos<1) return ;
int i,j;
char str_h[50];
char str_t[50];
for(i=0;i<pos;i++)
{
str_h[i]=s1[i];
}
str_h[i]='\0';
j=0;
while(s1[i])
{
str_t[j]=s1[i];
i++;
j++;
}
str_t[j]='\0';
strcpy(s1,str_h);
strcat(s1,s2);
strcat(s1,str_t);
}
void main ()
{
char st[50]="abcdefg";
printf("%s\n",st);
insert(st,"1234",4);
printf("%s\n",st);
}
运行结果
abcdefg
abcd1234efg
请按任意键继续. . .
#include <string.h>
void insert(char s1[ ],char s2[ ],int pos)
{
if(pos<1) return ;
int i,j;
char str_h[50];
char str_t[50];
for(i=0;i<pos;i++)
{
str_h[i]=s1[i];
}
str_h[i]='\0';
j=0;
while(s1[i])
{
str_t[j]=s1[i];
i++;
j++;
}
str_t[j]='\0';
strcpy(s1,str_h);
strcat(s1,s2);
strcat(s1,str_t);
}
void main ()
{
char st[50]="abcdefg";
printf("%s\n",st);
insert(st,"1234",4);
printf("%s\n",st);
}
运行结果
abcdefg
abcd1234efg
请按任意键继续. . .
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询