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.
struct node* mydelete(struct node *head) {
char name[21];
struct node *temp;
printf("---Please enter last name:");
scanf("%s", &name);
while (head->next != NULL) {
if (strcmp(head->last,name) == 0) {
temp = head;
head = head->next;
free(temp);
n--;
} else if (strcmp(head->next->last,name)==0) {
temp = head->next;
head->next = head->next->next;
free(temp);
n--;
} else
head = head->next;
}
return head;
}