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



我猜是一个简单的错误,但是当试图编译我的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 listn");
    }
    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;

更改

temp->(currentTable+i)->first = NULL; 

(temp->currentTable+i)->first = NULL; 

最新更新