0

我怎样才能为 char** str 设置一个空值,因为我有“越界指针的取消引用:1 个字节(1 个元素)超过数组 im 使用 C 语言的结尾”的错误

while(part)
    {
        res = (char**)realloc(res, (i + 1) * sizeof(char*));
        *(res + i) = mystrdup(part);

        part = mystrdup(strtok(NULL, delim));
        i++;
    }
    res = (char**)realloc(res, i * sizeof(char*));
    *(res + i) = NULL; // This is where I Encounter the ERROR
4

1 回答 1

2

在这部分代码中

res = (char**)realloc(res, i * sizeof(char*));
*(res + i) = NULL;

通过尝试访问*(res + i),您将一败涂地。你应该写

*(res + i -1) = NULL;

话说回来,

于 2016-01-13T10:42:06.363 回答