title: Struct is changing values by itself?
body: <blockquote>
    <p>bstsort.c</p>
  </blockquote>
  
  <pre><code>#include "header.h"
  
  /*
      I had to write my own string functions. 
      checkString = returns 1 if the strings are the same, 0 otherwise 
      checkGreaterString = returns 1 if arg1 comes before arg2, 0 otherwise
   */
  
  //insert a node
  int insertNode(struct NODE *root, char *compare, int cFlag)
  {
      // root node
       //printf("root -&gt; input : %s\n", root -&gt; input);
  
       //strings are the same
       if(checkString(root-&gt;input, compare, cFlag))
        {
            //printf("same string\n");
            root-&gt;isDuplicate++;  // count as duplicate 
            //printf("root input %s  and its duplicates is : %d\n", root-&gt;input, root-&gt;isDuplicate);
            return 0;
       }
       //strings are different
       else
       { 
           int check = checkGreaterString(root-&gt;input, compare, cFlag);
           //printf("check: %d\n", check);
           //compare comes before root
           if (check == 1)
           {
              // store compare at left node for root
              if(root -&gt; left == NULL){   
                  struct NODE *tempNode = malloc(sizeof(*tempNode));
                  tempNode -&gt;left = NULL;
                  tempNode -&gt; right = NULL;
                  tempNode -&gt; isDuplicate = 0;
                  tempNode -&gt; input = compare; //give node input
                  root -&gt; left = tempNode;     //set left node for root
                  //printf("left node : %s\n", tempNode -&gt; input);
                  //printf("left node duplicate : %d\n", tempNode-&gt;isDuplicate); 
                  //printf("left nodes parent %s\n", root -&gt; input);
                  return 0;
              }
              //left node is not empty, so insert node at that node 
              else
              {
                  printf("root -&gt; left -&gt; input %s\n", root -&gt; left -&gt; input);
                  printf("compare : %s\n", compare);
                  insertNode(root -&gt; left, compare, cFlag); 
                  return 0;
              }
           }
           //compare comes after root
           else if(check == 0)
           {
              // store compare at right node for root
              if(root -&gt; right == NULL){
                  printf("im in the right node\n");
                  struct NODE *tempNode = malloc(sizeof(*tempNode));
                  tempNode -&gt;left = NULL;
                  tempNode -&gt; right = NULL;
                  tempNode -&gt; isDuplicate = 0;
                  tempNode -&gt; input = compare;   //give node input
                  root -&gt; right = tempNode;     // set right node for root 
                  //printf("right -&gt; right -&gt; input : %s\n", root -&gt; right -&gt; input);
                  //printf("root -&gt; left -&gt; input %s\n", root -&gt; left -&gt; input);
                  //printf("right node duplicate : %d\n", tempNode-&gt;isDuplicate); 
                  //printf("right nodes parent %s\n", root -&gt; input);
                  return 0;
  
           }
           ////right node is not empty, so insert node at that node 
           else
               {  
                    //printf("im in the else for right node \n");
                    //printf("root-&gt;right-&gt;input%s\n", root -&gt; right -&gt; input);
                    insertNode(root -&gt; right, compare, cFlag); 
               }
          }
      }
  }
  </code></pre>
  
  <blockquote>
    <p>header.h</p>
  </blockquote>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;string.h&gt;
  
  struct NODE {
      struct NODE *left;
      struct NODE *right;
      char *input;
      int isDuplicate;
  };
  struct NODE root;
  </code></pre>
  
  <p>I'm trying to make a binary tree, using the input given by the user. The input functions are in another file, but they all work properly. My problem is with the structs, or more precisely setting the left and right node of a struct. Everytime I set the left/right node of the root with a specific input, the input changes without me explicitly changing it. I think the problem is with my <code>tempNode</code> pointer, but I'm not exactly sure what is the issue and how to fix it. </p>
  
  <p>Here is an example of the issue I spoke about above: </p>
  
  <p>Let's say the user enters "for". "for" becomes the root of the tree </p>
  
  <p>Then the user enters "ate". "ate" will become the left child of the root</p>
  
  <p>**** up to here this works. if i print the strings for my root and left node of my root they will give me the correct string *******</p>
  
  <p>Now, the user enters "test", "test" does become the right child of the root, but now when I print the left child it is also "test". the root string is still correct. </p>
  
  <p>Any help will be much appreciated. Thanks!</p>