title: Adding a node to a BST of strings
body: <p>This is for a school assignment. I get a seg fault when I try to add a new node to a BST. I think it may have something to do with how I've allocated the memory, but I can't figure out how to fix the issue.</p>
  
  <p>Struct code:</p>
  
  <pre><code>struct tnode {
    char* data;
    struct tnode* left;
    struct tnode* right;
  };
  
  typedef struct tnode Tnode;
  </code></pre>
  
  <p>Add node function:</p>
  
  <pre><code>Tnode* add_tnode(Tnode* current_tnode, char* value) {
    if (current_tnode == NULL) {
      malloc(sizeof(Tnode));
      current_tnode-&gt;data = value;
      current_tnode-&gt;left = NULL;
      current_tnode-&gt;right = NULL;
      return current_tnode;
        }
    else {
      if (strcmp(current_tnode-&gt;data, value) &lt;= 0) {
        add_tnode(current_tnode-&gt;left, value);
        return current_tnode-&gt;left;
        }
      else {
        add_tnode(current_tnode-&gt;right, value);
        return current_tnode-&gt;right;
        }
    }
  }
  </code></pre>
  
  <p>Main program to test the function:</p>
  
  <pre><code>int main() {
    Tnode* new_node =  (Tnode*)malloc(sizeof(Tnode));
    char* data1 = "Hello";
    char* data2 = "Goodbye";
    char* data3 = "Hi";
    char* data4 = "Bye";
    char* data5 = "Hey";
  
    add_tnode(new_node, data1);
    add_tnode(new_node, data2);
    add_tnode(new_node, data3);
    add_tnode(new_node, data4);
    add_tnode(new_node, data5);
  
    return 0;
  }    
  </code></pre>
  
  <p>This is the error I receive when I backtrace the segmentation fault:</p>
  
  <pre><code>#0  0x0000003458478350 in strcmp () from /lib64/libc.so.6
  #1  0x00000000004005be in add_tnode (current_tnode=0x601010, 
      value=0x400708 "Hello") at tree.c:16
  #2  0x0000000000400523 in main () at treetest.c:12
  </code></pre>
  
  <p>I'm thinking that when strcmp() tries to find the string stored in the node, it can't find it. Any help or tips would be very appreciated!</p>