title: Writing struct + saving only pointer?
body: <p>I am allocating space for the struct node in the variable n0. I save this struct to file using fwrite, but many people say that I'm only saving the pointer to the ustr. But I need save the string ustr, Could you help please?</p>
  
  <pre><code>typedef struct {
      unsigned char * ustr;
      int height;
  }node;
  
  void node_init(node * n, int r) {
  
      int i;
      n-&gt;ustr = malloc((r + 1) * sizeof(unsigned char));
      for (i = 0; i &lt; r; i++) {
          (n-&gt;ustr)[i] = random() &amp; 0xff;
      }
      (n-&gt;ustr)[r] = 0;
      n-&gt;height = -1;
  }
  void node_destroy(node * n) {
      free(n-&gt;ustr);
      n-&gt;height = -1;
  }
  
  int main() {
      FILE* file_ptr = fopen("file1", "w+");
      node n0;
      node_init(&amp;n0,2);
      fwrite(&amp;n0, sizeof(node), 1, file_ptr);
      fclose(file_ptr);
      node_destroy(&amp;n0);
      return 0;
  }
  </code></pre>