Pointers, linked list, array of pointers

S

Sean

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
 
T

Thomas Matthews

Sean said:
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?
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top