📌  相关文章
📜  将字符串插入到另一个字符串中 - C 编程语言代码示例

📅  最后修改于: 2022-03-11 15:04:43.395000             🧑  作者: Mango

代码示例1
// Insert q char c in pos n of the string str.
int strinsert(char **str, char c, int  n, int q)
{
    int len = my_strlen(*str);
    char ins[q + 1];
    char *new = malloc(len + q + 1);

    memset(ins, c, q);
    memset(new, 0, len + q);
    ins[q] = '\0';
    strncpy(new, *str, n);
    new[n] = '\0';
    strcat(new, ins);
    strcat(new, *str + n);
    return (0);
}

strinsert(&str, 'X', strlen(str) / 2, 5);
// Inserting in string str 5 'X' in the middle of the string