By this code I can't delete the first element of my linked list. Can anybody tell me how to fix it
// defining the linked list (basics)
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node* next;
};
void create(struct node **head, int data)
{
struct node **temp = head;
while (*temp != NULL)
{
temp = &(*temp) -> next;
}
(*temp) = (struct node*)malloc(sizeof(struct node));
(*temp) -> data = data;
(*temp) -> next = NULL;
}
void del(struct node *head, int data)
{
if (head -> data == data)
{
struct node *temp = head -> next;
free(head);
head = temp;
}
else
{
while ((head -> next -> data) != data)
{
head = head -> next;
}
struct node *prev = head;
free(head -> next);
struct node *next = head -> next -> next;
prev -> next = next;
}
}
void prnt(struct node *head)
{
while(head != NULL)
{
printf("%d",head -> data);
head = head -> next;
}
}
int main()
{
struct node *begin = NULL;
for (int i = 0; i < 10; i++)
{
create(&begin, i);
}
prnt(begin);
printf("\n");
del(begin,5);
prnt(begin);
printf("\n");
return 0;
}