Ive got a phonebook app that the user can enter in contact information, and it will show up in the phonebook. I have a delete function that allows the user to search via the last name and delete the contact from the phonebook. My issue is that when I search the last name to delete the contact, not only that contact, but also all the contacts that follow it.
void delete_contact(fr*friends ,int* counter, int i)
{
char name_search[50]={'\0'};
char Delete[5]={'\0'};
printf("Search by last name\n");
scanf("%s",name_search);
for(i=0;i<*counter;i++)
{
if(strcmp(name_search,friends[i].Last_Name)==0)
{
strcpy(friends[i].Last_Name,Delete);
(*counter)--;
}
}
}
Now I realize that I will need to write a few more strcpy
functions to overwrite the rest of the info within the contact connected to the last name, but right now I need to figure out why it's deleting all other names following in the phonebook. Ideas?
I can post more code or my output if needed. Thanks