I've been trying to creating singly linked list of strings but it does not work properly .But it works properly when I created linked list of integers. The first time its called perfectly. But when I execute the do while loop for second time by inputting choice=1 it messes up. The gets() does not accept the string from then
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#define ARR_MAX 20
struct node
{
char info[ARR_MAX];
struct node *next;
};
struct node *start=NULL;
void create()
{
struct node *temp=NULL,*ptr=NULL;
temp=(struct node *)malloc(sizeof(struct node));
if(temp==NULL)
{
printf("Out of Memory Space:\n");
exit(0);
}
else{
printf("Enter the data value for the node %d:\n",i);
i++;
gets(temp->info);
printf("%s \n",temp->info);
printf("ok \n");
temp->next=NULL;
}
if(start==NULL)
{
start=temp;
}
else
{
ptr=start;
while(ptr->next!=NULL)
{
ptr=ptr->next;
}
ptr->next=temp;
}
}
void display()
{
struct node *ptr;
if(start==NULL)
{
printf("List is empty:\n");
return;
}
else
{
ptr=start;
printf("The List elements are:\n");
while(ptr!=NULL)
{
printf("%s \t",ptr->info );
ptr=ptr->next ;
}
printf("\n");
}
}
int main(int argc, char const *argv[])
{
int choice;
do{
create();
printf("1.Create\n");
scanf("%d",&choice);
}while(choice==1);
display();
return 0;
}