Reputation: 2205
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;
}
Upvotes: 2
Views: 120
Reputation: 70981
Change
temp->(currentTable+i)->first = NULL;
to be
(temp->currentTable+i)->first = NULL;
Upvotes: 0
Reputation: 400139
Your syntax is off. You mean:
temp->currentTable[i].first = NULL;
temp->currentTable[i].bucketSize = 0;
Upvotes: 6