我猜这是一个非常简单的错误,但我在尝试编译我的 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/