Reputation: 6490
I would like to implement an array of linked lists (in order to implement a hash table).
I have a problem at the very beginning... I defined a linked list structure, and I initialized the array of linked lists like an array of pointer to a list : liste * Oblist[65003];
(Do i need to initialize it like this : liste * Oblist[65003] = {NULL};
?)
And I want to get the list at the index 12121 (which is NULL for the moment), so I did
liste L = *Oblist[12121] ;
The program compiles without errors but when I run it I get a Segmentation fault (core dumped)
Here is the whole code :
typedef struct Doublet {char * car ; struct Doublet * cdr ;}* liste ;
liste * Oblist[65003];
int main(void){
liste L = *Oblist[32123] ;
return 0;
}
Thank you in advance ;)
Upvotes: 0
Views: 129
Reputation: 28846
You have a few problems. liste
is typedef'ed as a pointer to a struct Doublet
, so it should be
liste Oblist[65003];
...
liste L = Oblist[32123];
Or, alternatively:
typedef struct Doublet { ... etc. } liste;
...
liste *Oblist[65003];
...
liste *list = Oblist[32123];
Upvotes: 1