C 在指针递增方面遇到麻烦(我认为)

标签 c arrays pointers compilation

我猜这是一个非常简单的错误,但我在尝试编译我的 C 代码时遇到了这个错误:

error: expected identifier before '(' token

从这段代码中,我尝试为哈希表设置结构,其中包含用于哈希冲突的链表:

typedef struct bN {
    MEntry nestedEntry;
    struct bN *next;
} bucketNode;

typedef struct bL {
    bucketNode *first;
    int bucketSize;
} bucket;

struct mlist {
    bucket *currentTable;
};

这段代码是我实际初始化链表的地方:

MList *ml_create(void){

    MList *temp;

    if (ml_verbose){
        fprintf(stderr, "mlist: creating mailing list\n");
    }
    if ((temp = (MList *)malloc(sizeof(MList))) != NULL){
        temp->currentTable = (bucket *)malloc(tableSize * sizeof(bucket));
        int i;
        for(i = 0; i < tableSize; i++){
            temp->(currentTable+i)->first = NULL; /**ERROR HERE*/
            temp->(currentTable+i)->bucketSize = 0; /**ERROR HERE*/
        }
    }
    return temp;

}

最佳答案

你的语法不对。你的意思是:

temp->currentTable[i].first = NULL;
temp->currentTable[i].bucketSize = 0;

关于C 在指针递增方面遇到麻烦(我认为),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13031600/

相关文章:

C++指针练习

c++ - 关于dup2和多线程的问题

c# - 如何编写一个vb.net代码来编译C/C++程序?

c - Glade 3.18.3 的 Windows 二进制文件?

c++ - 空指针数组

c++ - 创建指向 unsigned char[] 的指针并将其传递给 sf::SoundBuffer::loadFromMemory

c++ - XPath 表达式失败。 (C 中的 libxml2)

c - 从函数返回时保护 char[] 的最佳方法?

javascript - 手动编辑嵌套数组

java - 如何在循环中添加用户输入?