C语言面试题-字符串插入

来源:互联网 发布:mysql主外键约束语法 编辑:程序博客网 时间:2024/05/04 16:50

两个字符串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);}

如果有错误请指正。