title: initialization makes pointer from integer without a cast [enabled by default] while deleting a node in Binary tree
body: <p>I am trying to delete a node from binary tree. My logic for the first and second case (when left or right =NULL works fine) but i have problem in third case when i try to delete a node that contains  two subtree(left and right as well),What i try to do is:</p>
  
  <p>If the node value(is represented as "freq" in my code) is equal to the element to be deleted (represented as delete_val in my code, which is taken at terminal by user for an already existing tree).Then i go to the right most leaf of the left node and make it as successor and then replace it with the node that contains the value to be deleted.</p>
  
  <p>My code to do so is (which produces error, I have mentioned the line containing error in my code):</p>
  
  <pre><code>    delete_tree_node(int delete_val, node  **root)    
      {   
          node*temp1;    
          temp1=(*root);          
         if(delete_val==(temp1)-&gt;freq)    
         {    
            if(temp1-&gt;left==NULL)    
             {    
                 temp1=temp1-&gt;left;     
             }    
            else if(temp1-&gt;right==NULL)
             {    
                 temp1=temp1-&gt;right;    
             }    
            else    
             {     
   Line:73    node **successor= get_successor(&amp;temp1-&gt;left);    
              temp1-&gt;freq=(*successor)-&gt;freq;    
              delete_tree_node(temp1-&gt;freq,successor);     
             }    
         }      
         else if(delete_val&lt;temp1-&gt;freq)    
         {      
              delete_tree_node(delete_val,&amp;temp1-&gt;left);    
         }    
         else if(delete_val&gt;temp1-&gt;freq)    
         {        
               delete_tree_node(delete_val,&amp;temp1-&gt;right);    
         }
         (*root)=temp1;     
      }
  </code></pre>
  
  <p>where as the function get_successor() is :</p>
  
  <pre><code>Line:89     node**get_successor(node**suc)    
              {   
                node  *temp;    
                temp=*suc;     
                while(temp-&gt;right!=NULL)    
                 {    
                   temp=temp-&gt;right;    
                 }    
  Line:97       return (temp);    
              }
  </code></pre>
  
  <p>And call to delete_tree_node() is </p>
  
  <pre><code>delete_tree_node(delete_val,&amp;head);
  </code></pre>
  
  <p>The errors are as follows:</p>
  
  <pre><code>gcc cc.c -o cc    
  cc.c: In function ‘delete_tree_node’:    
  cc.c:73:26: warning: initialization makes pointer from integer without a cast [enabled by default]    
  cc.c: At top level:     
  cc.c:89:8: error: conflicting types for ‘get_successor’    
  cc.c:73:26: note: previous implicit declaration of ‘get_successor’ was here    
  cc.c: In function ‘get_successor’:    
  cc.c:98:4: warning: return from incompatible pointer type [enabled by default]
  </code></pre>
  
  <p>Could some one please help me in removing these errors and warning in order to delete the desired node from user ? Piece of code would be a big help to make as reference.</p>
  
  <p>Edit: I had not declared the function that's why it was giving the errors moreover i done <code>node*get_successor(node*suc)</code> removed one pointer and it worked fine on several samples i had tried except the one when i tried to do:
  Total number of nodes=4
  it just create duplicate in case if i take input like this (size =4) and nodes are: <code>1,12,14,55</code> and i am trying to delete "12" it deletes "12" but makes but makes a duplicate of "1" like<code>"1 1 14 55</code>". Do you know the reason for it ?In other cases it works fine(dont leave duplicate, this i was trying randomly and i found this problem)</p>
  
  <p>My edited code is:</p>
  
  <pre><code>#include &lt;stdio.h&gt;     
  #include &lt;stdlib.h&gt;     
  #include &lt;malloc.h&gt;     
  #include &lt;string.h&gt;        
  struct node     
  {     
      int freq;    
      struct node * left, * right;    
  };    
  typedef struct node node;    
  node* get_successor(node*suc);    
  
  void insert_first_node(int data, node * * Node)     
  {    
      node * temp1 = (node * ) malloc(sizeof(node));    
      temp1 -&gt; freq = data;    
      temp1 -&gt; left = NULL;    
      temp1 -&gt; right = NULL;      
      *Node = temp1;    
  }
  
  ////////////////////////////////////////////////////////////////////
  
  void insert_beginning(int data, node * * Node)     
  {    
       node *root;    
       root = * Node;    
      if (root == NULL)     
      {    
          insert_first_node(data,Node);    
          return;    
      }    
      if (data &lt;= root -&gt; freq)     
      {     
         insert_beginning(data,&amp;root-&gt;left);    
      } else     
      {    
         insert_beginning(data,&amp;root-&gt;right);    
      }     
  }
  
  //////////////////////////////////////////////////////////////////////////////
  
  print_tree(node*Node)    
  {    
   node * temp;     
   temp=Node;    
    if(temp!=NULL)    
    {    
      print_tree(temp-&gt;left);    
      printf(" %d  ",temp-&gt;freq);    
     print_tree(temp-&gt;right);    
     }    
  }
  
  /////////////////////////////////////////////////////////////////////////
  
  delete_tree_node(int delete_val, node  **root)    
  {    
      node*temp1;    
       temp1=(*root);     
      printf("check1\n");    
     if(delete_val==(temp1)-&gt;freq)    
     {    
          printf("check2\n");     
        if(temp1-&gt;left==NULL)    
         {    
             temp1=temp1-&gt;right;     
         }
  
       else if(temp1-&gt;right==NULL)    
        {    
            temp1=temp1-&gt;left;    
        }    
        else    
         {    
              node *successor= get_successor(temp1-&gt;left);    
          temp1-&gt;freq=(successor)-&gt;freq;    
             delete_tree_node(temp1-&gt;freq,&amp;successor);     
          }    
     }   
     else if(delete_val&lt;temp1-&gt;freq)    
     {     
          delete_tree_node(delete_val,&amp;temp1-&gt;left);    
      }    
      else if(delete_val&gt;temp1-&gt;freq)    
     {        
           delete_tree_node(delete_val,&amp;temp1-&gt;right);    
     }    
     (*root)=temp1;     
  }
      //////////////////////////////////////////////////////////////////////////////////////////////////////
  
  node* get_successor(node*suc)    
  {    
     node  *temp;    
     temp=suc;     
     while(temp-&gt;right!=NULL)    
     {    
       temp=temp-&gt;right;    
     }    
     return (temp);    
  }
  
  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  
  main()     
  {    
      int i, size, data,delete_val;    
      node * head;    
      head = NULL;    
      printf("How many  nodes are to be inserted ?\n");    
       scanf("%d", &amp; size);    
      for (i = 1; i &lt;= size; i++)    
      {    
          printf("enter the nodes \n");    
          scanf("%d", &amp; data);    
           insert_beginning(data, &amp; head);
      }    
           print_tree(head);    
           printf("\n");     
           printf("enter the node to be delted from the tree constructed before? \n");
  
               scanf("%d", &amp; delete_val);    
           delete_tree_node(delete_val, &amp; head);     
           print_tree(head);    
               printf("\n");    
  }
  </code></pre>
  
  <p>Edit: At last i got the reason for this wrong output of this duplicate the reason is in function <code>delete_tree_node(temp1-&gt;freq,&amp;successor);</code>  i must do <code>delete_tree_node(successor-&gt;freq,&amp;successor);</code>.</p>