ep.hobbyiest
Full Member level 4
hi,
i am trying this linked list code from two days. but i don't know where i m wrong...
plz tell me where i m wrong..
i am trying this linked list code from two days. but i don't know where i m wrong...
plz tell me where i m wrong..
Code:
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct Node
{
int data;
struct Node *next;
}node;
int main(void)
{
int i;
node *head,*tempp,*new_node;
head =(node*)malloc(sizeof(node));
head->data = 0;
head->next = NULL;
tempp = new_node = head;
head = head->next;
printf("\nstart\n");
for(i=1;i<5;i++)
{
head = (node*)malloc(sizeof(node));
if(head ==NULL)
printf("\nNo memory is allocated\n");
else
{
printf("\nMemory is allocated %d\n",i);
head->data = i;
head = head->next;
}
}
printf("\nDone\n");
head = NULL;
while(new_node!=NULL)
{
printf("Data : %d\n",new_node->data);
new_node = new_node->next;
}
printf("\nEnd of List\n");
return 0;
}