title: Why aren't root node values valid?
body: <p>I want to create a regression tree.
  Why can't I get valid values from root node after tree generation ?</p>
  
  <pre><code>/* 
   * File:   main.c
   * Author: C-AP
   *
   * Created on September 9, 2011, 8:06 PM
   */
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  typedef struct regnode {
      int setsize;
      int* set;
      int tokenpos;
      int nextsize;
      struct regnode** next;
  } regnode;
  
  /*
   * print array
   */
  void printliniar2(int dim, int* mat, char* label) {
      int i;
      printf("\n%s\n", label);
      for (i = 0; i &lt; dim; i++)
          printf(" %d ,", mat[i]);
      printf("\n");
  }
  
  /*
   * copies array source to array destination
   */
  void copyToInt(int dim, int* Source, int* Destination) {
      int i;
      for (i = 0; i &lt; dim; i++)
          Destination[i] = Source[i];
  }
  
  void getReducedSet(int dim, int* set, int delpos, int* newset){
      int i,j=0;
      for(i=0;i&lt;delpos;i++,j++)
          newset[j] = set[i];
      for(i=delpos+1;i&lt;dim;i++,j++)
          newset[j] = set[i];
  
  }
  
  void genTree(int setsize, int* set, int tokenpos, regnode* node){
  
      printf("\n**********************************\n");
  
      //allocate memory for node variable
      node = (regnode*)malloc(sizeof(regnode));
  
      //insert set dimension
      node-&gt;setsize = setsize;
      printf("node setsize : %d",node-&gt;setsize);
  
      //allocate set space
      node-&gt;set = calloc(node-&gt;setsize,sizeof(int));
  
      //insert set into node    
      copyToInt(setsize,set,node-&gt;set);
      printliniar2(node-&gt;setsize,node-&gt;set,"node set (copy)");
  
      //insert token position
      node-&gt;tokenpos = tokenpos;
      printf("\nnode tokenpos : %d\n",node-&gt;tokenpos);
  
      //insert number of next nodes
      node-&gt;nextsize = setsize - 1 - tokenpos;
      printf("\nnode nextsize : %d\n",node-&gt;nextsize);
  
      //allocate memory for next nodes
      node-&gt;next = malloc(node-&gt;nextsize*sizeof(regnode*));
  
      //create children nodes
      int i;
      for(i=0;i&lt;node-&gt;nextsize;i++){
          //create next node
          regnode* next;
  
          //get reduced set for child node
          int* newset = calloc(setsize-1,sizeof(int));
          getReducedSet(setsize,set,tokenpos+i,newset);
  
          //keep reference to next node
          node-&gt;next[i] = next;
  
          //recursively call genTree
          genTree(setsize-1,newset,tokenpos+i,next);
      }
  }
  
  /*
     void exploreTree(regnode* root){
     printf("\n**********************************\n");
     printf("\nnode setsize : %d\n",root-&gt;setsize);
     printliniar2(root-&gt;setsize,root-&gt;set,"set");
     printf("\nNumber of next nodes : %d\n",root-&gt;nextsize);
     int i;
     for(i=0;i&lt;root-&gt;nextsize;i++)
     exploreTree(root-&gt;next[i]);
     }
     */
  
  /*
   * 
   */
  int main(int argc, char** argv) {
      int dim = 5;
      int set[] = {1,2,3,4,5};
      int tokenpos=0;
      regnode* root;
  
      genTree(dim,set,tokenpos,root);
      //exploreTree(root);
  
      printf("\nSet dimension : %d\n",root-&gt;setsize);
      printliniar2(root-&gt;setsize,root-&gt;set,"set");
      printf("\nNumber of next nodes : %d\n",root-&gt;nextsize);
  
      return (EXIT_SUCCESS);
  }
  </code></pre>