So I working on creating a function called 'Create' that asks the user to enter numbers for a linked list. If the user types in 'Y', then ask to enter another element else if the user types 'N' stop and display the linked list, but I am having a bit of trouble. When I run it, it doesn't give me the option to type in Y or N and also when I type in N, it adds a 0 to the linked list. What is happening?
#include <stdio.h>
#include <stdlib.h>
//-------------------------------------------------
struct node {
int data;
struct node *next;
}*start=NULL;
//------------------------------------------------------------
void create() {
char ch;
do {
struct node *new_node,*current;
new_node=(struct node *)malloc(sizeof(struct node));
printf("Enter the data : ");
scanf("%d",&new_node->data);
new_node->next=NULL;
if(start==NULL) {
start=new_node;
current=new_node;
} else {
current->next=new_node;
current=new_node;
}
printf("Do you want to create another?(Y\N) ");
ch = getchar();
} while(ch!='N');
}
//------------------------------------------------------------------
void display() {
struct node *new_node;
printf("The Linked List : ");
new_node=start;
while(new_node!=NULL) {
printf("%d--->",new_node->data);
new_node=new_node->next;
}
printf("NULL\n");
}
//----------------------------------------------------
int main() {
create();
display();
}