Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pointers and Linklist help

Status
Not open for further replies.

Public32

IS-IT--Management
Feb 27, 2003
6
CA
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
 
Code:
firstPivotNode->connectedTo[0] = secondPivotNode;
I'm not sure what you're trying to do here? Why are you trying to store a node* pointer into an array of int* pointers?

What exactly do your node structs represent and what info are you storing in them?

Rather than building your own linked list, it would be a lot easier to use an STL list or vector.
 
ok, think of each node as a computer on a network. Each computer is connected to n number of other computers, like neighbours. So the whole point of firstPivotNode->connectedTo[] is to store these neighbours which in my program are the pointer addresses (since i am using link list). So to answer you question i am trying to store the pointer (memory) address of secondPivotNode in the first position of this array.

As I mentioned in my original post, I am wondering if there is a way to store the address of a pointer in an array of integers.
 
Well you could cast it to an int, but since you're storing node* pointers, you should be using an array of node* pointers instead:
Code:
node* connectedTo[50];
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top