Pointers and hashes

This is a discussion on Pointers and hashes within the C Programming forums, part of the General Programming Boards category; Here we go. So i passed a struct object into my hashtable with a key. The hashtable when called upon ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    12

    Pointers and hashes

    Here we go. So i passed a struct object into my hashtable with a key. The hashtable when called upon with the key returns a (void *). I want to set my local struct equal to the data at that (void *).

    This is what I think it should be but it doesn't seem to work.

    struct Foo p1=*(hstuff(table);

    Any help will be much appreciated.

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,638
    Well you could assign the void pointer returned by your hash function to another pointer of the appropriate type, but then I would wonder why you used void* in the first place. Why couldn't it return a struct?

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    12
    The hash can hold any object.

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    12
    It works if i do that. However, As soon as I try to access an element from the struct by doing p1->start I get a seg fault. It is just starting to ........ me off.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Ah, well your problem is on that line right there. That line below that other line? Yeah that's all wrong.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory allocation for GHash table
    By mukarj in forum C Programming
    Replies: 0
    Last Post: 01-15-2008, 10:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21