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[40],phone[20];
- struct node *next;
- }node;
- node *head=NULL;
- void insertlast(char n[], char p[])
- {
- node *nd=(node*)malloc(sizeof(node));
- nd->next=NULL;
- node *list=head;
- strcpy(nd->name,n);
- strcpy(nd->phone,p);
- if(head==NULL) head=nd;
- else{
- while(list->next!=NULL){
- list=list->next;
- }
- list->next=nd;
- }
- return;
- }
- void display(int n)
- {
- int i;
- node *list=head;
- printf("You have %d friends in your list\n",n);
- while(list!=NULL){
- printf("Friend %d:\nName: %s\nPhone: %s\n",++i,list->name,list->phone);
- list=list->next;
- }
- return;
- }
- int main()
- {
- int n,i;
- char name[40],phone[20];
- printf("Number of friends: ");
- scanf("%d",&n);
- printf("\n");
- for(i=1;i<=n;i++){
- printf("Enter the name: ");
- scanf(" %[^\n]",name);
- printf("\n");
- printf("Enter the phone number: ");
- scanf(" %[^\n]",phone);
- printf("\n");
- insertlast(name,phone);
- }
- display(n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement