我的双指针表没有完全返回我的函数假设用字符集拆分字符串

问题描述

char **ft_split(char *str,char *charset)
{
    int i = 0;
    int index = 0;
    int len;

    if (condition(str[0],charset) != 1)
        while (condition(str[index],charset) != 1)
            index++;

    while (condition(str[index],charset) == 1)
        index++;

    int tab = nbword(str,charset);
    printf("%d,len\n\n",tab);
    char **tableau = malloc((tab + 1) * sizeof(char));

    while (str[index] != '\0')
    {
        while (condition(str[index],charset) == 1)
            index++;

        len = wordlen(str,index,charset);
        tableau[i++] = malloc(len + 1 * sizeof(char));
        ft_strSPcpy(tableau[i - 1],str,len - 1,index);
        printf("tableau[%d] = %s\n",i - 1,tableau[i - 1]);
        index += len;
    }

    tableau[i] = 0;

    return tableau;

    free(tableau);
}

这是有东西阻挡的地方。

在main之前

tableau[0] =  bodeg
tableau[1] =  c vr
tableau[2] = iment 
tableau[3] = uper

in function main
tableau[0] =  tableau[last] = (null)

 c vr
iment 
uper

这就是我执行时得到的。

如你所见,在主函数中,第一个字符串是空的??发生了什么?

我也试过在我最后一段时间后看到,所有的字符串都很好。

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)