Hi Programmers,

Please help me in my project constructing a Phonebook program in c using linked lists with add,search,view and delete function.

Recommended Answers

All 6 Replies

What have you done so far? Could you show us that?

What have you done so far? Could you show us that?

This is my code its an array of structure program. I need to have this as a linked list program with a delete funtion..Please help

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>

struct info{
char name[50];
int TelNo;
};
struct info gab[50];
int rec=0;
char ch;
char search[50];
int c;
main()
{
	do{
	do{
		clrscr();
		printf("Phonebook");
		printf("\n1 Add\n2 View\n3 Search\n4 Exit\n");
		scanf("%c",&ch);
	}while((ch!='1') && (ch!='2') && (ch!='3') && (ch!='4'));

if(ch=='1')
{
	clrscr();
	printf("Enter Name: ");
	scanf("%s",&gab[rec].name);
	printf("\nEnter TelNo: ");
	scanf("%d",&gab[rec].TelNo);
	rec ++;
	}
	else if(ch=='2')
	{
	for(int i=0;i<rec;i++)
	{
	clrscr();
	printf("Directory #%d\n",i+1);
	printf("Name: %s",&gab[i].name);
	printf("\nTelNo: %d",&gab[i].TelNo);
	printf("\n==========");
	getch();
	}
	 }
	else if(ch=='3')
	{
	clrscr();
	printf("Enter Name to search: ");
	scanf("%s",&search);

	for(int z=0;z<rec;z++)
	{
	c=strcmp(search,gab[z].name);
	if(c==0)
	{
	printf("Name: %s",&gab[z].name);
	printf("\nTelNo: %d",&gab[z].TelNo);
	}
	getch();
	
	 }
	 }

	else

	exit(0);

	}while(ch!='4');
	return 0;
}

OK. Whatcha need?

OMG! Here comes my "Turbo-C-Knee-jerk"
I see you are using an outdated compiler. When we copy and paste your program in our compiler (unless someone has Turbo C), it won't run because your program uses outdated header files (conio.h)

I suggest you get Code::Blocks

Now, technically speaking, what you have done is not a linked list, but simply a list. You have not done the delete function. For an array, you have to shift all of the elements to one side. But for a linked list, deletion is very easy. Since you have asked for a linked version of the phone book problem, could you show us the linked list version, even if it's incomplete?

PS - Try to avoid using global variables

OMG! Here comes my "Turbo-C-Knee-jerk"
I see you are using an outdated compiler. When we copy and paste your program in our compiler (unless someone has Turbo C), it won't run because your program uses outdated header files (conio.h)

I suggest you get Code::Blocks

Now, technically speaking, what you have done is not a linked list, but simply a list. You have not done the delete function. For an array, you have to shift all of the elements to one side. But for a linked list, deletion is very easy. Since you have asked for a linked version of the phone book problem, could you show us the linked list version, even if it's incomplete?

PS - Try to avoid using global variables

I dont know how to write a linked list c program, thats why I need your help..

OK. Whatcha need?

I need to have this program as a linked list program with a delete function..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.