Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- //struct node.
- struct node
- {
- int data;
- struct node* next;
- };
- //prototype of create node function
- void create();
- //Global variable of startlist.
- struct node* startlist;
- int main (void)
- {
- //initially startlist pointer value is null
- startlist = NULL;
- create();
- return 0;
- }
- void create()
- {
- struct node *newnode, *temp;
- //variable c for checking if you want to increase the list, initial value is "y"
- char c = 'y';
- while (c=='y' || c=='Y')
- {
- //if it is start of list
- if (startlist == NULL)
- {
- newnode = (struct node *)
- malloc (sizeof (struct node));
- printf ("please enter Int\n");
- scanf ("%d", &newnode->data);
- newnode -> next = NULL;
- startlist = newnode;
- temp = newnode;
- }
- // If list has already created
- else
- {
- newnode = (struct node*)
- malloc (sizeof (struct node));
- printf ("please enter Int\n");
- scanf ("%d", &newnode->data);
- newnode-> next = NULL;
- temp ->next = newnode;
- temp = newnode;
- }
- // if want to increase the list reply with yes or no
- printf ("Want to enter more y/n?\n");
- scanf ("%c", &c);
- }
- printf ("Node is created\n");
- }
Add Comment
Please, Sign In to add comment