title: how to create a n-ary tree in c
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  
  struct node{
    char *word;
    int depth, children;
    struct node  **child;
  };
  
  typedef struct node node;
  
  
  node *createTree();
  node *createNode(char *word,int depth);
  
  int main(int argv,char *argc[]){
     node *root,*current_node;
     root=createNode("root",0);
     char *array[]={"string1","string2","string3"};
     current_node=root;
     printf("root has been created with word: %s \n",current_node-&gt;word);
     int i;
     for (i=0; i&lt;3; i++){
        current_node-&gt;child[i]=createNode(array[i],(current_node-&gt;depth)+1);
        current_node-&gt;children++;
        printf("%s  has been inserted to the tree\n",current_node-&gt;word);
     }
  
  }
  
  
  
  node *createTree(){
     printf("root has been created\n");
     return createNode("",0);    /*creates the first node*/
  }
  
  node *createNode(char *word,int depth){
     node *new_node;
     new_node=malloc(sizeof(node));
     new_node-&gt;word=word;
     new_node-&gt;depth=depth;
     new_node-&gt;children=0;
     new_node-&gt;child=NULL;
  }
  </code></pre>
  
  <p>So what i am trying to do here is build a n-ary tree. I use createNode function to create the children of the root but as soon as i am trying to link an adress of a new node to a child, the program crashes with segmentation fault. I know my mistake probably is,the way i try to create the children but i cant find. Help anyone?</p>