title: Function to remove entry from linked list in c
body: <p>I'm struggling with exercise 4 in chapter 10 of the Programming in C book by Kochan. </p>
  
  <p>The task is the following:</p>
  
  <blockquote>
    <p>Write a function called <code>removeEntry()</code> to remove an entry from a
    linked list. The sole argument to the procedure should be a pointer to
    the list. Have the function remove the entry after the one pointed to
    by the argument.</p>
  </blockquote>
  
  <p>For some reason the function doesn't work. If I do a <code>printf()</code> inside it, it seems to work, but it doesn't work in <code>main()</code>. I thought that given I am passing a pointer, it will change the original (as opposed to passing by value). But clearly I'm not doing it right. Could anyone please help me see where I'm going wrong?</p>
  
  <pre><code>// Function to remove an entry from a linked list
  
  #include &lt;stdio.h&gt;
  
  struct entry
  {
      int value;
      struct entry *next;
  };
  
  int main(void)
  {
      struct entry n1, n2, n3; // Original list
  
      struct entry *listPointer = &amp;n1; // List pointer set up for iterating list
  
      void removeEntry(struct entry *pList);
  
      //listHead.next = &amp;n1;  set list head to point to original beginning of list
  
      n1.value = 100;
      n1.next = &amp;n2;
  
      n2.value = 200;
      n2.next = &amp;n3;
  
      n3.value = 300;
      n3.next = (struct entry *) 0; // marks end of list
  
  
      // Print out values before removing entry
      printf("Before removing entry:\n");
  
      while (listPointer != (struct entry *) 0)
      {
          printf("%i\n", listPointer-&gt;value);
          listPointer = listPointer-&gt;next;
      }
  
      // reset listPointer to point to n1
      listPointer = &amp;n1;
  
      // run function (DOES NOT WORK)
      removeEntry(listPointer);
  
      // print out values after (supposedly) removing entry
      printf("\n\nAfter removing entry:\n");
  
      while (listPointer != (struct entry *) 0)
      {
          printf("%i\n", listPointer-&gt;value);
          listPointer = listPointer-&gt;next;
      }
  
      return 0;
  }
  
  /********************* REMOVE ENTRY ********************************/
  
  void removeEntry(struct entry *pList)
  {
      //  &lt;-------&amp;n2
      pList = pList-&gt;next;
  
  }
  </code></pre>