title: C - Linked List - Delete Node
body: <p>This is suppose to delete all the nodes containing the data "last" which is the same as the string "name". It is not giving me an error, but it is not working properly.It deletes more than what it needs to delete. </p>
  
  <pre><code>struct node* mydelete(struct node *head) {
      char name[21];
      struct node *temp;
  
      printf("---Please enter last name:");
      scanf("%s", &amp;name);
      while (head-&gt;next != NULL) {
          if (strcmp(head-&gt;last,name) == 0) {
              temp = head;
              head = head-&gt;next;
              free(temp);
              n--;
          } else if (strcmp(head-&gt;next-&gt;last,name)==0) {
              temp = head-&gt;next;
              head-&gt;next = head-&gt;next-&gt;next;
              free(temp);
              n--;
          } else
              head = head-&gt;next;
      }
  
      return head;
  }
  </code></pre>