# Thread: Member's value inside a binary tree

1. ## Member's value inside a binary tree

Hi all, I'm having this little problem right now. I know the answer must be pretty simple, but I just can't seem to find it. I create a binary tree with many nodes, each containing different members(name, number of msg, letf, right...). I'd like to modify these values but simply can't find the way to initialze them with a starting value nor to assign one to them. Anyway, here's what I'm talking about:

Here's the tree

Code:
```typedef struct node* PtrNode;
typedef struct node
{
char* name;               /* points on the name */
int nbMessSnt;               /* number of msg sent  */
int nbMessTrs;               /* number of msg transmited  */
int nbMessRec;                  /* number of msg received */
PtrNoeud left;                    /* points the left node */
PtrNoeud right;                   /* points the right node */
}Node;

PtrNode root = NULL;          /* root of the tree */```
What I'd like to do is asign the default value 0 to the messages. Does I have to do it when I add elements to the tree ? Right now, when I try to increase the number of messages of a member, the value I get is -842150451 which, I think, means it isn't initialized ?

Here the function that modify these values:
Code:
```int HandleMsg()
{
/* Open the file containing the messages */
FILE* fMessages = fopen("messages.txt", "r");

char value[30];
PtrNode sender = NULL;

while (!feof (fMessages))
{
/* each line of the file contains 2 name; the first is the sender, the 2nd the receiver */
/* first we find the sender in the tree */
sender= FindNode(root, value);
if (!sender) return 0;

/* we find the receiver. It must be in the subtree of the sender */

/* If both were found, we increase the number of sent and receive msg */
sender->nbMessExp++;
}
return 1;
}```
I also tried initializing the values when I created the tree:

Code:
```PtrNode CreeateTree()
{
FILE* fData = fopen("computers.txt", "r");

char value[30];
PtrNode new;

while (!feof (fData))
{
new->nbMessSnt = 0;
new->nbMessTrs = 0;
new->nbMessRec = 0;
if (!racine) racine = nouveau;
}
return racine;
}```
but it didn't worked well... Once I finished creating the tree and going throught it, the returned values were still -842150451.....

Got an idea what I might be doing wrong ?

Thanks, Frank

2. You're definitely working with uninitialized values, but it's hard to tell what's going wrong because you didn't supply enough of the right code. Try this: write a short test program that reads a small number of items into a tree. Make sure that the program still exhibits the problem, and post that code, including the binary tree code. But to avoid posting reams of source, make sure that it's bare bones.