0

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 ;)

2
  • You seem to confuse yourself with the typedefed pointer. You have an array of pointers to pointers of type struct Doublet. Commented Jul 29, 2014 at 22:32
  • Yep, probably, but I already used linked lists, several times, without problem. Commented Jul 29, 2014 at 22:33

1 Answer 1

1

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];
Sign up to request clarification or add additional context in comments.

3 Comments

Oh, seems like I'm a bit tired ;) Thanks for your answer!
Just one little question more : if I define my array of lists like this : liste Oblist[65003]; and I make it a global variable, how should I define in the other files this variable : extern + ... ? Thanks in advance ;)
I suppose that it is an other stupid question and the answer is extern list Oblist[60003], no?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.