title: Create Treenode with malloc in C
body: <p>I have troubles creating the rootnode of an Binary Search Tree.</p>
  
  <p>I defined the node in the headerfile bst.h: </p>
  
  <pre><code>#ifndef BST_H_
  #define BST_H_
  
  struct BST
  {
    int data;            /* data contained at root */
    struct BST *left; /* left node */
    struct BST *right; /* right node */
  };
  
  typedef struct BST BST;
  
  BST * bst_new (int data);
  
  #endif /* BST_H_ */
  </code></pre>
  
  <p>Here is the bst.c file :</p>
  
  <pre><code>#include "stdafx.h"
  #include "bst.h"
  #include &lt;stdio.h&gt;
  
  BST* bst_new(int data)
  {
      BST *new_node = (BST*)malloc(sizeof(BST));
      if (new_node == NULL)
      {
          fprintf(stderr, "Out of memory!!! (create_node)\n");
          exit(1);
      }
      new_node-&gt;data = data;
      new_node-&gt;left = NULL;
      new_node-&gt;right = NULL;
      return new_node;
  }
  </code></pre>
  
  <p>And now i try to create the Rootnode of the BST with: </p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;assert.h&gt;
  #include &lt;time.h&gt;
  
  #include "bst.h"
  
  
  int main ()
  {
      /* create new tree */
      BST *bst = bst_new(10);
  
      return 0;
  }
  </code></pre>
  
  <p>But i get an Error in bst.c saying that i make an "Write access violation" in line "new_node->data = data;".
  How can i get this thing working?</p>