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 receiver = NULL;
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 */
ReadData(fMessages , value);
sender= FindNode(root, value);
if (!sender) return 0;
/* we find the receiver. It must be in the subtree of the sender */
ReadDate(fMessages , value);
receiver= FindNode(sender, value);
if (!receiver) return 0;
/* If both were found, we increase the number of sent and receive msg */
sender->nbMessExp++;
receiver->nbMessRec++;
FindTransmitter(sender, receiver);
}
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))
{
ReadData(fData, value);
new= AddNode(root, value);
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