2

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;

}
Geesh_SO
  • 2,156
  • 5
  • 31
  • 58

2 Answers2

6

Your syntax is off. You mean:

temp->currentTable[i].first = NULL;
temp->currentTable[i].bucketSize = 0;
unwind
  • 391,730
  • 64
  • 469
  • 606
0

Change

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

to be

(temp->currentTable+i)->first = NULL; 
alk
  • 69,737
  • 10
  • 105
  • 255