0

char** str に null 値を設定するにはどうすればよいですか

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;

にアクセスしようとすると、 1 つずつオフに*(res + i)なります。あなたは書くべきです

*(res + i -1) = NULL;

そうは言っても、

于 2016-01-13T10:42:06.363 に答える