



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















(Advantages)
Exit Exit Phone Directory Delete Delete contacts Update Edit Contact Remove Remove a Contact Search Search a contact Add Add New Contact List List of Contacts in Phone Directory
#include <stdio.h> #include <stdlib.h> #include <string.h> struct node { char fname[ 100 ]; char lname[ 100 ]; long long int num; struct node *next; struct node *prev; }; struct node start,pre;
if(start==NULL) { new_node->next=NULL; start=new_node; } else { temp=start; while (temp->next !=NULL) { temp=temp->next; } temp->next=new_node; new_node->prev=temp; new_node->next=NULL; } printf("\n --New contact added successfully--\n"); }
11 void deletetop() { struct node *temp; if(start == NULL) { printf("\n No contacts to delete\n"); } else if(start->next == NULL) { start = NULL; free(start); printf("\n --Contact Deleted Successfully--
n"); } else { temp =start; start =start -> next; start -> prev = NULL; free(temp); printf("\n--Contact Deleted Successfully--
n"); } }
else { temp = start; while(temp->next!=NULL) { pre=temp; temp=temp->next; } pre->next=temp; temp -> prev -> next = NULL; free(temp); printf("\n--Contact Deleted Successfully--
n"); } }
void dspt() { struct node *pre, *temp; long long int spotnum; printf("Enter the number of the contact after which the contact is to be deleted:"); scanf("%lld",&spotnum); temp = start; while(temp -> num != spotnum) { temp=temp->next; if(temp -> next == NULL) { printf("\n No contacts to delete\n"); }
void display() { for (struct node * temp=start; temp!=NULL; temp=temp-
next){ printf("\n %s ",temp->fname); printf("%s\n",temp->lname); printf("\n %lld \n", temp->num ); } printf("\n-------No contacts below this---- \n"); }
void search() { struct node *temp; int i= 0 ,flag; long long int spotnum; temp = start; if(temp == NULL) { printf("\nPhonebook is empty\n"); } else { printf("\nEnter the number of the contact to be displayed:\n"); scanf("%lld",&spotnum);
int main(){ int c; printf("----------Welcome to the Phone Directory----------\n") ; printf(" What would you like to do?"); printf("!!Caution: Avoid using space and any other special characters while entering data for an error free execution!!"); while( 1 ){ printf("\n 1. Add new contact \n 2. Delete the first contact\n 3. Delete the last contact \n 4. Delete a specific contact \n 5. Display all contacts\n 6. Search for a specific contact\n 7. Exit\n"); printf("Enter your choice: "); scanf("%d",&c); switch (c) { case 1 : { entercontact(); break; } case 2 : { deletetop(); break; }
case 3 : { deletelast(); break; } case 4 : { dspt(); break; } case 5 : { display(); break; } case 6 : { search(); break; } case 7 : { printf("----Thank you for using the Phone Directory----"); exit( 0 ); break; } default: break; } } return 0 ; }