Thread: Chaining Hash Tables (in C)

  1. #16
    Deleted Account
    Join Date
    Mar 2005
    Posts
    57
    well, this assignment is an extension of a previous assignment. the first one was a basic singly list list and a binary tree. this assignment is a array with chained linked lists and a binary splay tree.

    i'm just unsure how to deal with array of pointers, which is why i'm struggling with it.

  2. #17
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    struct foo {
        int bar;
    };
    ...
    struct foo *baz;
    ...
    baz->bar = 10; /* segfault in the making */
    Baz doesn't actually point to an allocated instance of 'struct foo', so you can't try to access 'bar'.


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

  3. #18
    Deleted Account
    Join Date
    Mar 2005
    Posts
    57
    Code:
    struct foo {
        int bar;
    };
    ...
    struct foo *baz;
    ...
    baz->bar = 10; /* segfault in the making */

    hmmm...but that's not what i wrote....i think

    in main.c, i created an instance...of say in your example of foo, i.e foo newFoo, and then i pass it's address into a function, i.e &newFoo. Then i would do newFoo->bar = 10;

  4. #19
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by vdk_au
    hmmm...but that's not what i wrote....i think
    It's called teaching. I was showing you that you can't access the members of a structure via a pointer, if your pointer doesn't actually point to anything. Now let's look back at my last post, to see if you can make the connection:
    Quote Originally Posted by quzah
    Code:
    for(i=0; i<20; i++)
    {
       ov->array[i]->head = NULL;
       ov->array[i] = NULL;
    }
    "ov" has an array of poitnters. These pointers don't point at any actual instances, so you can't try to access "head". Doing so is why your program crashes.
    There's another problem with this code, that you'd have, if you actually allocated space. It would be a memory leak. But, since you didn't actually allocate anything for your array of pointers to point at, you get a crash.


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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Iterable hash tables
    By OnionKnight in forum Tech Board
    Replies: 5
    Last Post: 07-21-2008, 02:02 AM
  2. need help with hash tables with direct chaining
    By agentsmith in forum C Programming
    Replies: 4
    Last Post: 01-05-2008, 04:19 AM
  3. Hash tables - chaining
    By cosmo1996 in forum C Programming
    Replies: 2
    Last Post: 08-14-2007, 11:53 PM
  4. Group Project Help/Volunteer
    By DarkDot in forum C++ Programming
    Replies: 3
    Last Post: 04-24-2007, 11:36 PM
  5. Help with beginning hash tables, please.
    By Will in forum C++ Programming
    Replies: 8
    Last Post: 11-17-2002, 09:51 PM