Telephone Book Project

#include
#include
#include
#include
#include
#define null 0
void delay (int);

struct telephone_book
{
char name[20];
long unsigned int ph_no;
struct telephone_book *next;
};
typedef struct telephone_book T_BOOK;
T_BOOK *list=null;

void main()
{
T_BOOK *get_node(void);
int insert(T_BOOK *);
int display();
int modify(char []);
int del(char []);
int search(char []);
T_BOOK *node;
char name[20];

int choice;
clrscr();
printf("\n\n\n\t\t Telephone book using Link list");

do
{
printf("\n\n\n\t\t\t 1.Add a member");
printf("\n\n\t\t\t 2.Query a member");
printf("\n\n\t\t\t 3.Delete a member");
printf("\n\n\t\t\t 4.Modify a member");
printf("\n\n\t\t\t 5.List all member");
printf("\n\n\t\t\t 6.Exit");
printf("\n\n\n\t\t\t Enter your choice-> ");

scanf("%d",&choice);
fflush(stdin);

switch(choice)
{
case 1: node=get_node();
insert(node);
break;
case 2: printf("\n\n\t\t\t Enter the name to search-> ");
fflush(stdin);
scanf("%[^'\n']",name);
search(name);
break;
case 3: printf("\n\n\t\t\t Enter the name to delete :");
fflush(stdin);
scanf("%[^'\n']",name);
del(name);
break;
case 4: printf("\n\n\t\t\t Enter the name to modify :");
fflush(stdin);
scanf("%[^'\n']",name);
modify(name);
break;
case 5: display();
break;
case 6: exit(); break;
default : printf("\n\n\t\t\t Invalid choice...");break;

}
fflush(stdin);

} while(choice!=6);




getch();
}

T_BOOK *get_node()
{
T_BOOK *newnode;
newnode=(T_BOOK *)malloc(sizeof(T_BOOK));
newnode->next=null;
printf("\n\n\t\t\t Enter Name : ");
fflush(stdin);
scanf("%[^'\n']",newnode->name);
printf("\n\n\t\t\t Enter Phone no. : ");
fflush(stdin);
scanf("%lu",&newnode->ph_no);

return(newnode);



}

int insert(T_BOOK *node)
{
T_BOOK *ptr;
ptr=list;
if(ptr==null)
{
ptr=node;
list=ptr;
printf("\n\n\n\t\t\t New member aded...");
delay(1500);
return 1;
}
else
{
while(ptr->next!=null)
ptr=ptr->next;
ptr->next=node;
printf("\n\n\n\t\t\t New member aded...");
delay(1500);
return 1;
}
}


int display()
{
int i=1;
T_BOOK *ptr;
ptr=list;
printf("\n\n\t\t******* List of all your friends ******");
if(ptr==null)
{
printf("\n\n\t\t\t Phonebook is empty...");
delay(1500);
return 1;
}
while(ptr!=null)
{
printf("\n\n\n\t\t\t(%d) Name : %s",i++,ptr->name);
printf("\n\n\t\t\t Phone No. : %lu",ptr->ph_no);
ptr=ptr->next;
}
printf("\n\n\t\t***************************************");
delay(1500);
return 1;
}

int search(char name[])
{
T_BOOK *ptr;
ptr=list;

while(ptr!=null)
{
if(strcmpi(ptr->name,name)==0)
{
printf("\n\n\t\t\t Phone No. is = %lu",ptr->ph_no);
delay(1500);
return 1;
}
ptr=ptr->next;
}

printf("\n\n\t\t\t Name doesn't found....");
delay(1500);
return 0;
}


int del(char name[])
{
T_BOOK *ptr,*p;
ptr=list;
if(strcmpi(ptr->name,name)==0)
{
list=list->next;
printf("\n\n\n\t\t\t Data deleted...");
delay(1500);

return 1;
}
while(ptr!=null)
{

if(strcmpi(ptr->name,name)==0)
{
p->next=ptr->next;
free(ptr);
printf("\n\n\n\t\t\t Data deleted...");
delay(1500);
return 1;


}
p=ptr;
ptr=ptr->next;


}

printf("\n\n\t\t\t Name doesn't exist....");
delay(1500);
return 0;
}


int modify(char name[])
{
T_BOOK *ptr;
ptr=list;

while(ptr!=null)
{
if(strcmpi(ptr->name,name)==0)
{
printf("\n\n\t\t *** Persent Data *** ");
printf("\n\n\t\t\t Name : %s",ptr->name);
printf("\n\n\t\t\t Phone No. is = %lu",ptr->ph_no);
printf("\n\n\t\t *** Enter New Data ***");
printf("\n\n\n\t\t\t New Name : ");
fflush(stdin);
scanf("%[^'\n']",ptr->name);
printf("\n\n\t\t\t New Number : ");
scanf("%lu",&ptr->ph_no);

printf("\n\n\n\t\t\t Data modified...");
delay(1500);
return 1;

}
ptr=ptr->next;
}


printf("\n\n\t\t\t Name doesn't found....");
delay(1500);
return 0;

}
void delay (int x)
{

for(int i=0;i
}

Related Links :

No comments:

Post a Comment


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!