两个字符串s,t将t插入到s当中,s有足够的空间。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void insert(char *s,char *t, int i)
{
char *q = t;
char *p = s;
if (q == NULL) return ;
while(*p!='\0') {
if ( 0 >= --i ) {
printf("memove\n");
memmove(p+strlen(t),p,strlen(p));
break;
}
p++;
}
while(*q!=0) {
*p=*q;
p++;q++;
}
}
int main(void) {
char a[100]="Hewwwllo";
char b[10]="abc";
insert(a,b,5);
printf("%s\n",a);
}
如果有错误请指正。