title: Add ordered element recursively
body: <p>Why do i get segmentation fault on this code?</p>
  
  <pre><code>void inserord(Lint *li, int x, Lint *k){
  
      if(((*li)-&gt;value) &gt; x){
          Lint New;
          New = (Lint) calloc(1,sizeof(Nodo));
          New-&gt;value= x;
          New-&gt;next = (*li);
          (*k)-&gt;next = New;
          return;
  
      }else if(*li == NULL){
          return;
      }
      *k = *li;
      inserord( &amp;((*li)-&gt;next), x, &amp;(*k));
  }
  </code></pre>
  
  <p>The problem seems to be when i make *k = *li, they are pointers of the same type, Lint. </p>
  
  <p>This is the data structure:</p>
  
  <pre><code>typedef struct slist *Lint;
  
  typedef struct slist {
      int value;
      Lint next;
  } Nodo;
  </code></pre>
  
  <p>The idea on the *k, is to pass the previous node to the next recursive call, so i can link this old structure to the new one, and the new to the next.</p>
  
  <p>EDIT: </p>
  
  <p>this is the full code:</p>
  
  <pre><code>typedef struct slist *Lint;
  
  typedef struct slist {
      int value;
      Lint next;
  } Nodo;
  
  void inserord(Lint *li, int x, Lint *k){
      if(((*li)-&gt;value) &gt; x){
          Lint New;
          New = (Lint) calloc(1,sizeof(Nodo));
          New-&gt;value= x;
          New-&gt;next = (*li);
          (*k)-&gt;next = New;
          return;
  
      }else if(*li == NULL){
          return;
      }
      *k = *li;
      inserord( &amp;((*li)-&gt;next), x, &amp;(*k));
  }
  
  void insertend(Lint *l, int x){
      Lint new, aux;
  
      new = (Lint) calloc(1,sizeof(Nodo));
      new-&gt;value = x;
      new-&gt;next = NULL;
  
      if(*l==NULL){
          *l=new;
          return;
      }
      else
      {
          for(aux=*l; aux!=NULL ; aux = aux-&gt;next){
              if(aux-&gt;next == NULL){
                  aux-&gt;next = new;
                  return;
              }
          }
      }
  }
  
  int main(){
      Lint listinha;
  
      printf("\n");
  
      insertend(&amp;listinha, 1);
      insertend(&amp;listinha, 2);
      insertend(&amp;listinha, 3);
      insertend(&amp;listinha, 4);
      insertend(&amp;listinha, 5);
      insertend(&amp;listinha, 7);
  
      listVal(&amp;listinha);
  
      Lint k = NULL;
  
      inserord(&amp;listinha, 4, &amp;k);
  
      listVal(&amp;listinha);
  
      return 0;
  } 
  </code></pre>