Array of pointers

This is a discussion on Array of pointers within the C++ Programming forums, part of the General Programming Boards category; Hi, im using visual c++ and I am getting run time errors whenever i try this problem. What i am ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    36

    Array of pointers

    Hi, im using visual c++ and I am getting run time errors whenever i try this problem.

    What i am trying to do it create an array of linked lists. So for example in array[x][y] I would like to store the node at the head of the list.

    Could someone advise me how to declare this array and how to use it / pass it to functions?

    Thank you


    - this is a piece of code im using now. This function takes the pointerarry, an x-y coordination and number to put in the linked list.
    Code:
    void createlist(int x, int y, int value, nodeptr *pointerarray[9][9]){
    
    	nodeptr hdList;
    	hdList = new node;
    	hdList->number = value;
    	hdList->next = NULL;
    	pointerarray[x][y] = &hdList;
    }

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    It looks like you are trying to store the address of the local pointer, rather than a pointer to the allocated node.

    Perhaps this works better:

    Code:
    void createlist(int x, int y, int value, nodeptr pointerarray[9][9]){
    
    	nodeptr hdList;
    	hdList = new node;
    	hdList->number = value;
    	hdList->next = NULL;
    	pointerarray[x][y] = hdList;
    }
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    36
    great man! thank you. It seems to be doing what I want now

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    Suggestion: Avoid typedefing type* things because it makes the code less readable, especially when used wrong. I see not harm in typing type* instead of typeptr.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Returning an Array of Pointers to Objects
    By randomalias in forum C++ Programming
    Replies: 4
    Last Post: 04-29-2006, 02:45 PM
  2. two-dimensional dynamic array of pointers to classes
    By Timo002 in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 06:18 AM
  3. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 05:58 PM
  4. array of pointers to struct array
    By eth0 in forum C++ Programming
    Replies: 1
    Last Post: 01-08-2004, 05:43 PM
  5. array of pointers to structs
    By stumon in forum C Programming
    Replies: 7
    Last Post: 03-24-2003, 06:13 AM

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