字符串插入函数

来源:互联网 发布:淘宝千牛咋登录不了 编辑:程序博客网 时间:2024/05/13 06:51

方法一

void strnins(char *s, char *t, int i){    if (i<0 && i>strlen(s)){        printf("Position is out of bounds. \n");    }    if (!strlen(s))        strcpy(s,t);    else if (strlen(s))    {        strcat(t, (s + i));        strcpy((s+i),t);    }}

方法二

void strnins(char *s, char *t, int i){    char string[MAXSIZE], *temp = string;    if (i<0 && i>strlen(s)){        printf("Position is out of bounds. \n");    }    if (!strlen(s))        strcpy(s, t);    else if (strlen(s))    {        strncpy(temp,s,i);        strcat(temp,t);        strcat(temp,(s+i));        strcpy(s,temp);    }}
0 0
原创粉丝点击