#include <stdio.h>#include <string.h>#define LEN 20/*将src插入至des的pos处*/void insertStr (char *des, char *src, int pos) { char *posp = des+pos; /*指向des之pos处的指针*/ char front[LEN],back[LEN]; /*暂存字符串*/ int i; i=0; while (des<posp) /*des前半段转录至front*/ front[i++] = *des++; front[i] = '\0'; /*标识字符串结束*/ des -= pos; /*des退回原字符串首*/ i=0; while (*posp) /*des后半段转录至back*/ back[i++] = *posp++; back[i] = '\0'; /*标识字符串结束*/ strcat(front,strcat(src,back)); /*三段字符串连接至front*/ strcpy (des,front); /*front赋值至des*/ }int main(void) { char s1[LEN],s2[LEN]; int pos; puts ("请输入s1:"); gets (s1); putchar ('\n'); puts ("请输入s2:"); gets (s2); putchar ('\n'); puts ("================================================================"); putchar ('\n'); pos = strlen (s1)/2; insertStr (s1,s2,pos); puts ("将s2插入至s1中间处:"); puts (s1); putchar ('\n'); getch (); return 0;}运行结果