I want to just create a linklist.The program below goes into an endless
loop.The srange behaviour is that i can exit from the program if i create
only two nodes.After two goes into infinite loop.
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node* next;
};
typedef struct node sn;
int create (sn *);
//int add(sn *);
//int delete(sn *);
//int length(sn *);
int main()
{
sn *head;
printf("Create a list");
head =(sn*)malloc(sizeof(sn));
create(head);
return 0;
}
int create(sn *temp)
{
int i=0;
printf("Enter data element:");
scanf("%d",&temp->data);
printf("To continue press 1:");
scanf("%d",&i);
while (i==1)
{
temp->next = (sn*)malloc(sizeof(sn));
temp = temp->next;
create(temp);
}
temp->next = NULL;
return 0;
}