#include "stdio.h"typedef struct{ char ch[40]; int len;}SString;void StrInsert(SString *s,int pos,SString *t){ int i; if(pos<0||pos>s->len) printf("pos is err\n"); if(s->len+t->len<=40) { for(i=s->len-1;i>=pos;i--) s->ch[i+t->len]= s->ch[i]; for(i=pos;i<t->len+pos;i++) s->ch[i]=t->ch[i-pos]; s->len=s->len+t->len; } else printf("insert is err\n");}void InitStr(SString *s){ int i=0; char k[40]; scanf("%s",k); for(i;k[i]!=0;i++) s->ch[i]=k[i]; s->len=i; }void main(){ void StrInsert(SString *s,int pos,SString *t); void InitStr(SString *s); SString *a,*t; InitStr(a); InitStr(t); StrInsert(a,2,t); printf("%s\n%d",a->ch,a->len);}
for(i=s->len-1;i>=pos;i--) s->ch[i+t->len]= s->ch[i];/*这个地方的怎么加不上去啊。。。
for(i=s->len;i>=pos;i--)
InitStr()里给s->ch[i]赋值之前没有先为s分配空间……