title: Deleting first and last element of a linked list in C
body: <pre><code>struct person 
  {
      int age;
      char name[100];
      struct person *next;
  };
  
  void delfirst(struct person **p)// For deleting the beginning
  {
      struct person *tmp,*m;
      m = (*p);
          tmp = (*p)-&gt;next;
      free(m);
      return;
  
  }
  void delend(struct person **p)// For deleting the end
  {
      struct person *tmp,*m;
      tmp=*p; 
      while(tmp-&gt;next!=NULL)
      {
          tmp=tmp-&gt;next;
      }
      m-&gt;next=tmp;
      free(tmp);
      m-&gt;next = NULL;
      return;
  
  }
  </code></pre>
  
  <p>I'm looking for two separate functions to delete the first and last elements of a linked list. Here is what I tried. What do you suggest? Especially deleting first is so problematic for me.</p>