首页 > 解决方案 > 我的双指针表没有完全返回。我的功能是假设用字符集拆分字符串

问题描述

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);
}

这就是东西阻塞的地方。

在主要之前

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

这就是我在执行时得到的。

如您所见,在主函数中,第一个字符串为空?发生什么事了 ?

在我最后一段时间之后,我也试着看看,所有的弦都很好。

谢谢你

标签: cpointerscharset

解决方案


推荐阅读