title: Returning formatted string from C function
body: <p>I'm trying to write a recursive function for printing a tree-like structure. What I want to do is roughly as follows. Assume <code>form</code> is a function that takes the same arguments as <code>printf</code>, but returns the formatted string instead of printing it; <code>Node</code> is the struct that the structure is built from, with a <code>val</code> slot storing an unsigned long.</p>
  
  <pre><code>char* vals(Node* u) {
      if (leaf(u)) {
          return form("%lu", u-&gt;val);
      } else {
          return form("%s, %s", vals(u-&gt;left), vals(u-&gt;right);
      }
  }
  </code></pre>
  
  <p>I'm not sure how to write this, as I've not been able to find a function similar to <code>form</code>.</p>