title: C: how to print a list in reverse order?
body: <p>I am trying to print a list of <code>tree_nodes</code> in reverse order:</p>
  
  <p>Current prompt example: <code>/helloFellow/hello/root / &gt;</code></p>
  
  <p>Desired result: <code>root/hello/helloFellow / &gt;</code></p>
  
  <p>What is a way to do this efficiently?</p>
  
  <pre><code>// *prints the prompt (e.g. /bar/baz/ &gt;) in every iteration of the main loop
  // *show all directories on the path in correct order
  void show_prompt(struct tree_node *cwd) {
      struct tree_node *parDir = cwd-&gt;parent;
      struct tree_node *originalDir = cwd;
  
      while (cwd-&gt;parent != NULL) {
          printf("/");
          printf("%s", cwd-&gt;parent-&gt;string_buffer);
          cwd = cwd-&gt;parent;
      }
      cwd = originalDir;
      printf("/ &gt;");
  }
  </code></pre>