Pointers, linked list, array of pointers

Discussion in 'C++' started by Sean, Sep 24, 2006.

  1. Sean

    Sean Guest

    Hi
    I have the following code:
    struct node{
    int ID;
    bool connected;
    int *connectedTo[50];
    int numConnectedTo;
    int numMsgsRecieved;
    int overwhelmed[20][20];
    node *nxtNode;
    };

    void main(){
    ..
    ..
    ..

    }

    void createNetwork(node *headNode){
    node * firstPivotNode = headNode;
    node * secondPivotNode = headNode->nxtNode;
    ..
    ..
    ..

    firstPivotNode->connectedTo[0] = secondPivotNode;
    ..
    ..
    ..
    }

    my problem is in "int *connectedTo[50]" in the struct.
    As you can see I have created a linked list and i want the connectedTo
    array to store the address to x numbers (less than 50) of links. But it
    is not working. I guess the problem is that since the type of
    secondPivotNode is a node * I can't store it is "address" in an int
    array.

    In fact I can't even do the following

    int test = firstPivotNode;

    which is wierd because I can do this:

    cout << firstPivotNode;

    and it prints the address where firstPivotNode is pointing to.

    any possible suggestions?

    Thanks
    Sean, Sep 24, 2006
    #1
    1. Advertising

  2. Sean wrote:

    > Hi
    > I have the following code:
    > struct node{
    > int ID;
    > bool connected;
    > int *connectedTo[50];
    > int numConnectedTo;
    > int numMsgsRecieved;
    > int overwhelmed[20][20];
    > node *nxtNode;
    > };

    You may find that separating the data from the link
    field is a Good Idea. The Good Idea would lead to
    a generic linked list module.

    Speaking of generic linked lists, have you looked
    at the Standard Template Library (STL) lately?
    Hint: #include <list>


    >
    > void main(){
    > .
    > .
    > .
    >
    > }

    Fatal flaw. The main() function _ALWAYS_ returns
    an int. Always. See also <cstdlib>, EXIT_SUCCESS,
    and EXIT_FAILURE.


    > void createNetwork(node *headNode){
    > node * firstPivotNode = headNode;
    > node * secondPivotNode = headNode->nxtNode;
    > .
    > .
    > .
    >
    > firstPivotNode->connectedTo[0] = secondPivotNode;
    > .
    > .
    > .
    > }
    >
    > my problem is in "int *connectedTo[50]" in the struct.
    > As you can see I have created a linked list and i want the connectedTo
    > array to store the address to x numbers (less than 50) of links. But it
    > is not working. I guess the problem is that since the type of
    > secondPivotNode is a node * I can't store it is "address" in an int
    > array.
    >
    > In fact I can't even do the following
    >
    > int test = firstPivotNode;
    >
    > which is wierd because I can do this:
    >
    > cout << firstPivotNode;
    >
    > and it prints the address where firstPivotNode is pointing to.
    >
    > any possible suggestions?
    >
    > Thanks
    >


    You need to review your data types and keep them consistent.
    > node * secondPivotNode = headNode->nxtNode;
    > ...
    > firstPivotNode->connectedTo[0] = secondPivotNode;

    The member "connectedTo" is type integer.
    The variable "secondPivotNode" is of "struct node *".
    An integer cannot receive a struct node *.


    --
    Thomas Matthews

    C++ newsgroup welcome message:
    http://www.slack.net/~shiva/welcome.txt
    C++ Faq: http://www.parashift.com/c -faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    http://www.comeaucomputing.com/learn/faq/
    Other sites:
    http://www.josuttis.com -- C++ STL Library book
    http://www.sgi.com/tech/stl -- Standard Template Library
    Thomas Matthews, Sep 24, 2006
    #2
    1. Advertising

  3. Sean

    loufoque Guest

    Sean wrote :
    > Hi
    > I have the following code:
    > struct node{
    > int ID;
    > bool connected;
    > int *connectedTo[50];


    node* connectedTo[50] maybe ?
    loufoque, Sep 24, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Ritchey
    Replies:
    7
    Views:
    476
    emerth
    Jul 10, 2003
  2. Chris Ritchey

    Generating a char* from a linked list of linked lists

    Chris Ritchey, Jul 9, 2003, in forum: C Programming
    Replies:
    7
    Views:
    463
    emerth
    Jul 10, 2003
  3. fool
    Replies:
    14
    Views:
    502
    Barry Schwarz
    Jul 3, 2006
  4. joshd
    Replies:
    12
    Views:
    665
    John Carson
    Oct 2, 2006
  5. jawdoc
    Replies:
    9
    Views:
    748
    Chris Thomasson
    Mar 10, 2008
Loading...

Share This Page