This code is actually an excerpt from my addressbook program..
address_count monitors the number of contacts added.
Current_record monitors the input's position in the array.
Anyway, here it is.
Code:
void del_contact(int *address_count, int *current_record)
{
int get, del, i, j;
printf("\nEnter the number of entry/contact you want to delete.\n");
printf("For example:\nIf you want to delete your first input type '1'\n");
printf("Contact number:");
scanf("%d", &get);
del = get-1;
//for loop to assign '/0' as the content for the given entry
for(i=0; i<6; i++)
{
strcpy(addressbook[i][del], addressbook[6][0]); //address book[6][0] has no value
}
(*address_count)--; //since you're gonna delete an entry
if((*current_record)>0)
{
(*current_record)--;
}
for(i=0; i<6; i++)
{
for(;get<=(*address_count-get);get++)
{
strcpy(addressbook[i][get-1],addressbook[i][get]);
}
}
}
Code:
for(i=0; i<6; i++)
{
for(;get<=(*address_count-get);get++)
{
strcpy(addressbook[i][get-1],addressbook[i][get]);
}
}
Here's my problem.
This code is supposed to copy the strings from the next array to the array to be deleted. Which means that if there's an entry(addressbook) in arrays 1, 2 and 3 and I want to delete array 1, array 2 will go be copied to array 1 and array 3 to array 2 so that the program runs smoothly..
But this doesn't work. D: any idea where I'm wrong? What should I do? Thanks a lot!