Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have this assignment in C programing: Programming assignment (100 pts): Write

ID: 664706 • Letter: I

Question

I have this assignment in C programing:

Programming assignment (100 pts): Write a program that uses an array of structures to hold contact information for your friends. The program should allow the user to enter as many friends as the user wants. Create functions to add or delete entries in the phone book and to print valid phone book entries. Do not display phone book entries that are invalid or NULL (0). You can assume that all people have unique names. Make sure you allocate and free memory as necessary.  
Output example:
Phone Book Application 1) Add friend

2) Delete friend

3) Show phone book  
What do you want to do: 1

First name: Bob

Last name: Smith

Phone number: 123-4567

Record added to the phone book

I submitted something that didn't work, my instructor corrected it. This is the code I got back from my instructor:

#include
#include
#include
#include
#include
typedef struct _person
{
    char fname[35];
    char lname[35];
   
    long int mble_no;
   
}person;

void menu();
void got();
void start();
void back();
person* addrecord(person*);
void listrecord(person*);
void modifyrecord();
person* deleterecord(person*);
void searchrecord(person*);

int count=0;

int main()
{
    system("color 5f");
    start();
    return 0;
}
void back()
{
    start();
}
void start()
{
    menu();
}

void menu()
{
int selection = 0;
person* book = (person*)malloc(sizeof(person));

while(selection != 5){

  //system("cls");
  printf(" WELCOME TO Greg's PHONEBOOK");

  printf(" MENU ");
  printf(" 1.Add New 2.List 3.Delete 4.Search 5.Exit ");
  scanf("%d",&selection);

  switch(selection)
  {
   case 1:
    book = addrecord(book);
       break;
   case 2:
     listrecord(book);
       break;
   case 3:
    book = deleterecord(book);
       break;
   case 4:
    searchrecord(book);
    break;
   case 5:
    exit(0);
       break;
   default:
          system("cls");
          printf(" Enter 1 to 4 only");
          printf(" Enter any key");
  }
}
}

person* addrecord(person* book)
{
person* tmp = (person*)realloc(book,(count+1)*sizeof(person));

if(tmp == NULL){
  printf("Out of memory ");
  return(book);
}
book = tmp;
printf(" First name: ");
scanf("%s", book[count].fname);
printf("Last name: ");
scanf("%s", book[count].lname);
printf("Phone number: ");
scanf("%d", &book[count].mble_no);

count++;

return(book);
}

void listrecord(person* book)
{
int i;
for(i=0; i   printf("%s %s %d ",book[i].fname,book[i].lname,book[i].mble_no);
  
}
}

person* deleterecord(person* book){

int i,j;
char lname[35];
char fname[35];

printf("Enter the first name to delete ");
scanf("%s",fname);

printf("Enter the last name to delete ");
scanf("%s",lname);

for(i=0; i   if((strcmp(book[i].fname,fname) == 0)&& (strcmp(book[i].lname,lname) == 0)){
   
   for(j=i+1; j     
    strcpy(book[j-1].fname,book[j].fname);
    strcpy(book[j-1].lname,book[j].lname);
    book[j-1].mble_no = book[j].mble_no;
    
   }
   printf("Record has been deleted ");
   count--;
   if(count != 0)
    book = (person*)realloc(book,(count)*sizeof(person));
   return(book);
  }
  
}

printf("Record could not be found ");
return(book);

}

void searchrecord(person* book){

int i;
char lname[35];
char fname[35];

printf("Enter the first name to search ");
scanf("%s",fname);

printf("Enter the last name to search ");
scanf("%s",lname);

for(i=0; i   if((strcmp(book[i].fname,fname) == 0)&& (strcmp(book[i].lname,lname) == 0)){
   printf("Record: %s %s %d ",book[i].fname,book[i].lname,book[i].mble_no);
   break;
  }
}

if(i== count)
  printf("Record could not be found ");
}

/*
void searchrecord()
{
    struct person p;
FILE *f;
char name[100];

f=fopen("project","rb");
if(f==NULL)
{
    printf(" error in opening");
    exit(1);

}
printf(" Enter name of person to search ");
got(name);
while(fread(&p,sizeof(p),1,f)==1)
{
    if(strcmp(p.name,name)==0)
    {
        printf(" Detail Information About %s",name);
        printf(" Name:%s Mobile no:%ld ",p.name,p.mble_no);
    }
        else
        printf("file not found");

}
fclose(f);
printf(" Enter any key");

getch();
    system("cls");
menu();
}

*/
/*
void modifyrecord()
{
    int c;
    FILE *f;
    int flag=0;
    struct person p,s;
char name[50];
f=fopen("project","rb+");
if(f==NULL)
  {

   printf("CONTACT'S DATA NOT ADDED YET.");
   exit(1);


  }
else
{
     system("cls");
  printf(" Enter CONTACT'S NAME TO MODIFY: ");
            got(name);
            while(fread(&p,sizeof(p),1,f)==1)
            {
                if(strcmp(name,p.name)==0)
                {

                    printf(" Enter name:");
                    got(s.name);
                   
                    printf(" Enter phone no:");
                    scanf("%ld",&s.mble_no);
                  
                    fseek(f,-sizeof(p),SEEK_CUR);
                    fwrite(&s,sizeof(p),1,f);
                    flag=1;
                    break;

                }
                fflush(stdin);


            }
            if(flag==1)
            {
                printf(" your data id modified");

            }
            else
            {
                    printf(" data is not found");

            }
            fclose(f);
}
printf(" Enter any key");
getch();
    system("cls");
menu();

}
*/
/*
void got(char *name)
{

   int i=0,j;
    char c,ch;
    do
    {
        c=getch();
                if(c!=8&&c!=13)
                {
                    *(name+i)=c;
                        putch(c);
                        i++;
                }
                if(c==8)
                {
                    if(i>0)
                    {
                        i--;
                    }
                   // printf("h");
                    system("cls");
                    for(j=0;j                     {
                        ch=*(name+j);
                        putch(ch);

                    }

                }
    }while(c!=13);
      *(name+i)='';
}
*/

The new assignment is to modify this code to do the following:

1) Alphabetically sort the list of entries by name (first or last).

2) Find a phone number for a given name.

3) Randomly select a friend from the phonebook for you to call.

4) Delete everyone from the phonebook at the same time.

Can someone make the modifications and post by 5 pm 7/10/15?

Explanation / Answer

#include #include #include //STRUCTURE FOR PHONE BOOK ENTRIES typedef struct phone { char fname[10]; char lname[10]; char addr[30]; char phonum[15]; char email[30]; }emp; //INITIALIZING FUNCTIONS void add(emp *, int); void print(emp *, int); void remove(emp *, int); //MAIN FUNCTION main() { int e; //amount of entries in phone book int sel=0; // user input emp emp1[20]={''}; printf("How many entries do you want in your phone book? "); scanf("%d", &e); fflush(stdin); while(sel!=5) { printf(" Select what you want to do to the phone book: "); //shows user different options and allows user to enter input printf("1: Add an entry "); printf("2: Delete an entry "); printf("3: Print all entries "); printf("4: Randomly select a friend to call "); printf("5: Exit program "); printf(" Enter number: "); scanf("%d", &sel); switch(sel) { case 1: add(emp1, e); break; case 2: remove(emp1, e); break; case 3: print(emp1, e); break; default: sel=5; printf(" You are leaving the program! "); } } system("PAUSE"); return 0; } //FUNCTION TO ADD ENTRY void add(emp * emp1, int n) { char fname[10]; char lname[10]; char addr[30]; char phonumm[15]; char email[30]; int i = 0; char t[3]={''}; printf(" You are entering a new phone book entry! "); printf("Enter first name: "); scanf("%s", &fname); fflush(stdin); printf(" Enter last name: "); scanf("%s", &lname); fflush(stdin); printf(" Enter address: "); scanf("%s", &addr); fflush(stdin); printf(" Enter phone number: "); scanf("%s", &phonumm); fflush(stdin); printf(" Enter email: "); scanf("%s", &email); fflush(stdin); for(int c = 0; i=0; c++) { if(strcmp(emp1[c].fname, t)==0) //makes sure it enters data only if element is empty { strcpy(emp1[c].fname, fname); strcpy(emp1[c].lname, lname); strcpy(emp1[c].addr, addr); strcpy(emp1[c].phonum, phonumm); strcpy(emp1[c].email, email); i = 1; } } } //FUNCTION THAT PRINTS OUT ADDRESSES IN FUNCTIONS void print(emp * emp1, int n) { char t[3]={''}; printf(" You are printing out your phonebook!"); for(int x=0; x