简体   繁体   中英

C Having Trouble with Pointer Incrementing (I think)

Quite a simple error I guess but I get this error when trying to compile my C code:

error: expected identifier before '(' token

From this code where I am trying to set up structs for a hash table with linked lists for hash collisions:

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

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

struct mlist {
    bucket *currentTable;
};

And this code where I actually initialise the linked list:

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;

}

Your syntax is off. You mean:

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

Change

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

to be

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM