title: Printing the structure of n-ary array in C
body: <p>My homework for my c course is to implement a menu as a n-ary tree. I have to create a <code>struct</code>, populate it with data and print the data. 
  Although creating a struct and populating were relatively easy, I have found the struggle with printing. My goal is to print the structure in this manner: </p>
  
  <pre><code>  1 File
        1.1 Open
        1.2 Save As
        1.3 Save as Other
           1.3.1 Text
           1.3.2 Word or Excel Online
        1.4 Send File
           1.4.1 Attach to Email
           1.4.2 Send &amp; Track
        1.5 Close
  </code></pre>
  
  <p>My struggle is that I can't find a way how to: 
  a) Add spaces after each child.
  b) Add number for each child of the child.</p>
  
  <p>My structure looks like this: </p>
  
  <pre><code>typedef struct node
  {
      long nodeID;
      long parentNodeID;
      char name[100];
      struct node *next;
      struct node *child;
  } node;
  </code></pre>
  
  <p>My failed attempt to accomplish this :</p>
  
  <pre><code>void printMenu(node* root){
      if(root == NULL) {
          fprintf(stderr, "Root has not been initialised");
          exit(1);
      }
      if(root-&gt;parentNodeID == 0){
          printf("%ld %s",root -&gt; nodeID,root -&gt; name);
          fflush(stdout);
          printMenu(root-&gt;child);
      }
      if(root-&gt;child){
          printf("%6ld.%ld %s",root-&gt;parentNodeID,root-&gt;nodeID - 1,root-&gt;name);
          fflush(stdout);
          printMenu(root-&gt;child);
      }
  
  
  
      printf("%5ld.%ld %s",root-&gt;parentNodeID,root-&gt;nodeID - 1,root-&gt;name);
      fflush(stdout);
      printMenu(root -&gt; next);
  
  }
  </code></pre>
  
  <p>Please send help :(</p>