# Thread: Help with deleting node in the middle of a linked list

1. ## Help with deleting node in the middle of a linked list

I am trying to delete a node in the middle of my linked list. I am having some trouble...anyone see where my problem is?

Code:
```void *cancelFlight(struct llnode **flight, char firstName[], char lastName[])
{
struct llnode *newlist;
struct llnode *current;
int stop = 0;

current = (struct llnode*) malloc(sizeof(struct llnode));
newlist = (struct llnode*) malloc(sizeof(struct llnode));

current = *flight;
newlist = *flight;

if(strcmp(current->lastName, lastName) == 0 && strcmp(current->firstName,firstName) == 0)
{
newlist = newlist->next;
*flight = newlist;
}
else
{
while(stop == 0)
{
current = current->next;
if(strcmp(current->lastName, lastName) == 0 && strcmp(current->firstName,firstName) == 0)
{
current = current->next;
newlist->next = current;
*flight = newlist;

stop = 1;
}
}

}

}```

2. > current = (struct llnode*) malloc(sizeof(struct llnode));
> newlist = (struct llnode*) malloc(sizeof(struct llnode));
What are these for?
Why are you casting malloc (see the FAQ)

> while(stop == 0)
All linked list code should have as a minimum
while ( current != NULL )

> I am trying to delete a node in the middle of my linked list
The essence of which is being able to perform the assignment
prev->next = current->next;
free( current );

That is, you make the previous node point past the current node (rather than to the current node), then delete the current node.

The tricky bits are handling say the first node in the list.

3. Code:
```        temp = (*HEAD)->link;