Question
Programming assignment (100 pts): You have worked very hard on your phonebook program for many weeks and it is becoming a popular application with all
Programming assignment (100 pts): You have worked very hard on your phonebook program for many weeks and it is becoming a popular application with all your friends. You decide you want to compete with facebook.com and the next upgrade of your phonebook software should make contact data accessible even if the user closes your application and returns to it at a later time. Add additional functionality to your phonebook program from lab# 7. Make it possible for users to: 1) Store all entries in the phonebook into a location/file-name specified by the user. 2) Retrieve entries from the location/file-name specified by the user. If the user does not explicitly specify a path to the file, a default location of your choosing should be used.
This is my current code:
#include
void ADD(); void Delete1(); void Display1(); void Alphabetical1(); void Number1(); void Random1(); void DeleteAll1(); typedef struct Phone_Book_List { char *FName; char *LName; char *PhoneNumber1; } list;
typedef struct Delete_Entry { char *FName; char *LName; } take;
//Pointer list *lt1; take *tk1; //globally int cnt = 0; int delCnt = 0; int main(void)
{ //Variables int iSel; do { printf(" PHONE BOOK: "); printf("1) ADD FRIEND "); printf("2) DELETE FRIEND "); printf("3) DISPLAY PHONE BOOK "); printf("4) SORT ALPHABETICALLY "); printf("5) FIND PHONE NUMBER "); printf("6) RANDOM CONTACT "); printf("7) DELETE ALL CONTACTS "); printf("8) EXIT "); printf("WHAT DO YOU WANT TO DO? "); scanf("%d", &iSel); switch (iSel) { case 1: //Add ADD(); break; case 2: //Delete Delete1(); break; case 3: //Display Display1(); break; case 4: //Sort Alphabetical1(); break; case 5: //Find Number1(); break; case 6: //Random Random1(); break; case 7: //Delete all DeleteAll1(); break; case 8: //Quit break; default: printf(" Invalid selection "); break; } } while (iSel != 8); free(tk1); free(lt1); tk1 = NULL; lt1 = NULL; return 0; } //FUNCTION void ADD() { char *leftName; if (cnt == 0) { lt1 = (list *) malloc ((cnt*25) + 25); } else { lt1 = (list *) realloc (lt1, (cnt*50) + 50); } if (lt1 == NULL) { printf("YOU CANNOT ADD MORE MEMORY "); } else { lt1[cnt].FName = (char *) malloc(sizeof(char)*15); lt1[cnt].LName = (char *) malloc(sizeof(char)*15); lt1[cnt].PhoneNumber1 = (char *) malloc(sizeof(char)*15); printf(" ENTER FIRST NAME: "); scanf("%s", lt1[cnt].FName); printf(" ENTER LAST NAME: "); scanf("%s", lt1[cnt].LName); printf(" ENTER PHONE NUMBER: "); scanf("%s", lt1[cnt].PhoneNumber1); printf(" CONTACT ADDED "); } cnt++; } //Deletes Contact void Delete1() { int i; int q = 0; char *uName; if (delCnt == 0) { tk1 = (take *) malloc ((delCnt*25) + 25); } else { tk1 = (take *) realloc (tk1, (delCnt*1) + 1); } if (tk1 == NULL) { printf("Out of memory can not Delete "); } else { tk1[delCnt].FName = (char *) malloc(sizeof(char)*15); tk1[delCnt].LName = (char *) malloc(sizeof(char)*15); printf(" ENTER THEIR FIRST NAME: "); scanf("%s", tk1[delCnt].FName); printf(" ENTER THEIR LAST NAME: "); scanf("%s", tk1[delCnt].LName); }
for (i = 0; i < cnt; i++) { if (lt1[i].FName == NULL && lt1[i].LName == NULL) continue; if (strcmp(lt1[i].FName, tk1[delCnt].FName) == 0&& strcmp(lt1[i].LName, tk1[delCnt].LName) == 0) { printf(" %s %s has been deleted ", lt1[i].FName, lt1[i].LName); lt1[i].FName = NULL; lt1[i].LName = NULL; lt1[i].PhoneNumber1 = NULL; q = 1; break; } }
if (q != 1) { printf(" Contact not in the Phonebook "); }
delCnt++; cnt--;
}
void Display1() { int i;
printf(" CONTACTS: ");
for (i = 0; i < cnt; i++) { if (lt1[i].FName != NULL && lt1[i].LName != NULL) { printf(" %s %s: %s ", lt1[i].FName, lt1[i].LName, lt1[i].PhoneNumber1); } } system("pause"); }
//Alphabetically void Alphabetical1() { int i; int j; char temp[50][50];
printf(" CONTACTS: ");
for (i = 0; i < cnt; i++) { for (j = i + 1; j < cnt; j++) { if (strcmp(lt1[i].LName, lt1[j].LName) > 0) { strcpy(temp[i], lt1[i].LName); strcpy(lt1[i].LName, lt1[j].LName); strcpy(lt1[j].LName, temp[i]); } } }
for (i = 0; i < cnt; i++) printf(" %s %s: %s ", lt1[i].FName, lt1[i].LName, lt1[i].PhoneNumber1);
system("pause"); }//End function void Number1() { int i; int q = 0; char fName[25]; char lName[25];
printf(" Enter First Name: "); scanf("%s", fName); printf(" Enter Last Name: "); scanf("%s", lName);
for (i = 0; i < cnt; i++) { if (strcmp(lt1[i].FName, fName) == 0 && strcmp(lt1[i].LName, lName) == 0) { printf(" %s %s's PHONE NUMBER IS: %s ", lt1[i].FName, lt1[i].LName, lt1[i].PhoneNumber1); q = 1; break; } }
if (q != 1) { printf(" Not in the Phonebook "); } system("pause"); }
void Random1() { srand(time(NULL)); int iRandomNum; iRandomNum = (rand() % cnt) + 1; printf("%s %s: %s ", lt1[iRandomNum].FName, lt1[iRandomNum].LName, lt1[iRandomNum].PhoneNumber1); system("pause"); }
void DeleteAll1() { int i; for (i = 0; i < cnt; i++) { do{ lt1[i].FName = NULL; lt1[i].LName = NULL; lt1[i].PhoneNumber1 = NULL; break; } while (i <= cnt); } printf(" ALL CONTACTS DELETED "); system("pause"); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started