I need a node to point to multiple children (I don't know how many of which I have at compile time).
for the time being I only need the father node to point to at least one child.
but it's pointing to '0', what have I missed?
here is my code
#include <bits/stdc++.h>
using namespace std;
string tokens[10];
typedef struct node
{
char* value;
node* children[10]={NULL};
}node;
void connect(node* father,node* child)
{
// child = (node*) malloc(sizeof(node*));
if(father->children[0]!=NULL)
father->children[0]=child;
cout<<father->children[0]<<endl;
}
int main()
{
node* father_ = (node*) malloc(sizeof(node*));
node* child_ = (node*) malloc(sizeof(node*));
cout<<"before\n";
connect(father_,child_);
cout<<"after\n";
father_->children[0]->value="a";
cout<<child_->value;
}