title: Delete a item from linked list in c
body: <p>How can I delete a Item from a linked list in c.</p>
  
  <pre><code>typedef struct
  {
      int n;
      struct item *nexI;
  
  } item;
  
  
  #define na 1000
  int n, j;
  </code></pre>
  
  <p>I have in my main:</p>
  
  <pre><code>item * list[na];
  
  n = 5;
  
  for(j = 0; j &lt; na; j++)
      remove_elem(list, n, j);
  </code></pre>
  
  <p>now my function remove_elem:</p>
  
  <pre><code>void remove_elem(item * list[], int n, int pos)
  {
      int i;
      item * aux;
      item * sec;
  
  
      aux = list[pos]-&gt;nexI;
  
      if(aux == NULL)
          return;
      else
      {
          sec = (item *)aux-&gt;nexI;
  
          if(aux-&gt;n == n)
          {
          list[pos]-&gt;nexI = sec;
              return;
          free(aux);
          }
  
          while(sec != NULL)
          {
  
              if(sec-&gt;n == n)
              {
                  aux-&gt;nexI = sec-&gt;nexI;
                  free(sec);
                  return;
              }
          aux = (item *) aux-&gt;nexI;
          sec = (item *) sec-&gt;nexI;
          }
      }
  </code></pre>
  
  <p>}</p>
  
  <p>but this code is giving me a segmentation fault and i cant notice why, can u figure it what I'm doing wrong here?</p>