Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- typedef struct node
- {
- char name[20];
- char phone[20];
- struct node *next;
- } node;
- node *head=NULL;
- void insert_at_last()
- {
- node *n=(node*)malloc(sizeof(node));
- n->next=NULL;
- printf("Enter Name:");
- scanf(" %[^\n]",n->name);
- printf("Enter his Phone NO:");
- scanf(" %[^\n]",n->phone);
- if(head==NULL)
- {
- head=n;
- }
- else
- {
- node *list=head;
- while(list->next!=NULL)
- {
- list=list->next;
- }
- list->next=n;
- }
- return;
- }
- void display(int x)
- {
- int count=1;
- printf("You have %d friend in your list\n",x);
- node *list=head;
- while(list!=NULL)
- {
- printf("Friend %d:\n",count);
- printf("Name:%s\n",list->name);
- printf("Phone No:%s\n",list->phone);
- printf("\n");
- list=list->next;
- count++;
- }
- return;
- }
- int main()
- {
- int x;
- printf("Number Of friends:");
- scanf("%d",&x);
- int i;
- for(i=0; i<x; i++)
- {
- insert_at_last();
- }
- display(x);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement