#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);}
#include<stdio.h>#include<string.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"); return; } if(s->len+t->len>=40) { printf("insert is err\n"); return; } for(i=s->len-1;i>=0;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+=t->len; s->ch[s->len]=0;}void InitStr(SString *s) { scanf("%s", &s->ch); s->len = strlen(s->ch);}void main() { SString a, t; InitStr(&a); InitStr(&t); StrInsert(&a, 2, &t); printf("%s\n%d", a.ch, a.len);}