Apply data structures by building and using advanced data types in C language.

Sigchi4life
Category:
Programming
Price: $5 USD

Question description

I need help to fix my code. I don't need the entire code.

Create a program that creates a structure array to hold contact information for your friends. The program should allow the user to enter up to five friends and print the phone book’s current entries. Create functions to add entries in the phone book and to print valid phone book entries. Do not display phone book entries that are invalide or NULL (0).

This is my code:

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

typedef struct PhoneBook_Contacts

{

char FirstName[20];

char LastName[20];

char PhoneNumber[20];

} phone;

void AddEntry(phone*);

void DeleteEntry(phone*);

void PrintEntry(phone*);

char deleteFirstName[20]={'\0'};

char deleteLastName[20]={'\0'};

char deletePhoneNumber[20]={'\0'};

int x=0;

int counter=0;

phone phonebook[500];

int main(void)

{

int iSelection=0;

while(iSelection!=4)

{

printf("\n\t\t\tPhonebook Menu");

printf("\n\n\t(1)\tAdd Friend");

printf("\n\t(2)\tDelete Friend");

printf("\n\t(3)\tDisplay Phonebook Entries");

printf("\n\t(4)\tExit Phonebook");

printf("\n\nWhat would you like to do?");

scanf("%d",&iSelection);

if(iSelection==1)

{

AddEntry(phonebook);

}

if(iSelection==2)

{

DeleteEntry(phonebook);

}

if(iSelection==3)

{

PrintEntry(phonebook);

}

if(iSelection==4)

{

printf("The Phonebook will now exit.");

system("cls");

}

}

}

void AddEntry(phone*phonebook)

{

counter++;

phonebook=malloc(counter*sizeof(phone));

printf("First Name:");

scanf("%s",phonebook[counter-1].FirstName);

printf("Last Name:");

scanf("%s",phonebook[counter-1].LastName);

printf("Phone Number:");

scanf("%s",phonebook[counter-1].PhoneNumber);

printf("\n\nFriend successfully added to Phonebook");

}

void DeleteEntry(phone*phonebook)

{

counter++;

printf("First Name:");

scanf("%s", deleteFirstName[counter-1]);

printf("Last Name:");

scanf("%s",deleteLastName[counter-1]);

for(x=0;x<counter;x++)

{

printf("Friend successfully deleted from Phonebook");

}

else

{

printf("Invalid Entry");

}

}

void PrintEntry(phone*phonebook)

{

printf("Phonebook Entries:\n]n");

for(x=0;x<counter;x++)

{

printf("\t(%d)\n",x+1);

printf("\t%s %s\n",phonebook[x].FirstName,phonebook[x].LastName);

printf("\t%s\n",phonebook[x].PhoneNumber);

}

}



Tutor Answer

(Top Tutor) Daniel C.
(997)
School: Duke University
PREMIUM TUTOR
Studypool has helped 1,244,100 students
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1820 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors