My code is not working as it supposed to do. code compile with no errors but it doesn't give the output as expected
What's wrong with the code
Code:
#include<stdio.h>
#include<stdlib.h>
struct node
{
int x;
struct node *next;
};
int main ()
{
struct node *current = NULL;
struct node *last = NULL;
struct node *head = NULL;
current = malloc(sizeof(*current));
last = malloc(sizeof(*last));
while ( current!= NULL)
{
current->x = 10;
current->next = last;
current->x = 30;
current->next = NULL;
}
head = current;
while (head != NULL)
{
printf("%d\n", head->x);
head = head-> next;
}
return 0;
}