Thread: Accessing a node

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    68

    Accessing a node

    Right now, I'm getting a Segmentation Fault on the last 2 lines of this code. For the moment, I'm attempting to store x1 and y1 into array_ptr[num]->x and array_ptr[num]->y respectively.

    I separated the functions with lines of "///".

    I cannot access the nodes from main, it has to be from this function. I did have the function set up a different way, but I figured this would be much easier to read.

    I hope I'm not leaving anything out...

    Would it be possible to get some help with this? Thanks.
    Last edited by madmax2006; 10-07-2009 at 09:38 AM.

  2. #2
    Registered User
    Join Date
    Dec 2008
    Posts
    32
    In functiion make_array(int _c, NODEPTR *array_ptr):

    array_ptr = malloc(_c*sizeof(NODEPTR));


    That malloc() call isn't going to change the value of array_ptr to the caller, which is what you wanted. So make_array() allocates all that pretty memory then immediately loses track of it, never to be seen again.

    Guess you need yet _another_ level of indirection for that call? hehe

    Careful, before long you'll have a typedef for NODEPTRPTRPTR.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    68
    Thanks for the help!

    I figured out the rest
    Last edited by madmax2006; 10-07-2009 at 09:39 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help Debugging my AVL tree program.
    By Nextstopearth in forum C Programming
    Replies: 2
    Last Post: 04-04-2009, 01:48 AM
  2. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM