Hello,
I created a structure with two nodes in it, one that points to the next node and the other points to previous node:
Why is the second printing not working??? :confused:Code:#include<stdio.h>
typedef struct node
{
int value;
struct node *next;
struct node *prev;
}node;
int main(void)
{
node *head = NULL;
int i;
head = malloc(sizeof(node));
head->value = 1;
head->prev = NULL;
for (i = 2; i < 11; i++)
{
head->next = malloc(sizeof(node));
head->next->prev = malloc(sizeof(node));
head->next->prev = head;
head = head->next;
head->value = i;
}
head->next = NULL;
while(head != NULL)
{
printf("%d\n",head->value);
head = head->prev;
}
/*Not working*/
while(head)
{
printf("%d\n",head->value);
head = head->next;
}
system("pause");
return 0;
}