void ins(char string[]){
char sted[20],stringed[80];
int pos,stedlength,strlength;
int i;
printf("String to insert> ");
fflush(stdin);
gets(sted);
printf("Position of insertion> ");
scanf("%d",&pos);
stedlength=strlen(sted);
strlength=strlen(string);
for(i=0;i<strlength+stedlength;i++){
if(i>=pos&&i<stedlength+pos)
stringed[i]=sted[i];
else if(i<pos)
stringed[i]=string[i];
else if(i>=stedlength+pos)
stringed[i]=string[i-stedlength];
}
stringed[i]='\0';
strlength=strlen(stringed);
for(i=0;i<strlength;i++)
string[i]=stringed[i];
}
在上面的for_loop裏面,沒辦法順利的把字串存到stringed裏面
理想例子:string[] = "Hello! How are you!", sted[] = " Peter", pos=5
理想輸出是Hello Peter! How are you!
不知道字串跟loop要怎樣配搭,求解答
謝謝