左值需要作为赋值的左操作数吗?

lvalue required as left operand of an assignment?

这是我的代码:

void pwd(Fs_sim *files) {
    Node *curr_node = files->curr;
    Node **space = NULL;
    int i = 0;

    while (curr_node->parent != NULL) {
        space = realloc(space, sizeof(Node *) * (i + 1));
        *space + i = curr_node;
        i++;
        curr_node = curr_node->parent;
    }
    if (i == 0)
        printf("/\n");
    else {
        while (i > 0) {
            printf("/%s", (*space + i--)->name);
        }

        printf("\n");
    }
    free(space);

}

'space' 是指向正在动态分配的数组的指针。当每个节点被迭代时,我想在动态分配的数组中存储一个指向该节点的指针,并计算有多少元素。我收到错误消息:

error: lvalue required as left operand of an assignment

关于'*space + i = curr_node;'行。

我看不出有什么问题。有人可以澄清一下吗?

更新:

我已经更改了代码,它现在可以编译了,但是当我 运行 可执行文件时,我得到了 segmentation fault。这是我的代码:

void pwd(Fs_sim *files) {
    Node *curr_node = files->curr;
    Node **space = NULL;
    int i = 0;

    while (curr_node->parent != NULL) {
        space = realloc(space, sizeof(Node *) * (i + 1));
        *(space + i) = curr_node;
        i++;
        curr_node = curr_node->parent;
    }
    if (i == 0)
        printf("/\n");
    else {
        while (i >= 0) {
          printf("/%s", (*(space + (i-1)))->name);
          i--;
        }

        printf("\n");
    }
    free(space);

}

还是找不到问题所在

提前致谢。这里是 C 的大菜鸟。

更新前答案:

你好像颠倒了,应该是curr_node = *space + i。这是因为您要分配的表达式的值应该在左侧的变量,因为您不能将 curr_node 分配给两个变量之和

这不太适合你的目的,你也可以*(space + i) = curr_node

我认为的错误在这里:

while (i >= 0) {
    printf("/%s", (*(space + (i-1)))->name);
    i--;
}

i 为 0 而您尝试执行 (*(space + (i-1)))->name); 时会发生什么?

你得到了space + -1