具体操作间代码中注释部分!!!
方法一:
#include<stdio.h>
#include<string.h>
#define MAX 100
/*
在字符串str的第pos个位置之前插入另一个字符串T
pos从1开始,且 1<= pos <= strlen(str) + 1
例如:str = "hello", T = "world";
当 pos=1; 在字符串头前插入,即 worldhello;
当 pos = strlen(str) + 1; 在字符串末尾插入,即 helloworld
当 pos = 3; 在字符串中间插入,即 heworldllo
strinsert函数作用:
先将下标为pos-1的字符一直到末尾的字符全部向后移动一位
再将下标为pos-1的字符替换成'\0',上述pos=3时,即he\0llo\0
先输出he,紧接着输出插入的字符串world,最后输出llo,即heworldllo
*/
void strinsert(char *str, int pos, char *T) {
if (pos < 1 || pos > strlen(str) + 1)
return 0;
for (int i = strlen