//Preconditions: The first parameter is an integer array; the
second parameter is an integer representing the number
of elements in the array; the third parameter is the
number that is to be deleted from the array; and the
fourth parameter is the index from which the search for
deletion should start.
//Postconditions: The function deletes all elements
whose value is equal to item starting from the index
loc. The size of the array will decrease if one or more
copies of item existed in the array. Therefore function
changes the number of elements in the array as well. The
function also returns the number of deleted items.
int delete_elemet(int a[], int *n, int item, int loc);
I suggest doing this with a testing program...
Code:
//Stick this somewhere in the code...
void printArray (int a[], int n)
{
int i;
printf ("Array: ");
for (i = 0; i < n; i++) printf ("%d ", a[i]);
printf ("\n");
}
// And your main could look something like this...
int main ()
{
int array[] = {3, 4, 5, 4, 3, 3, 3, 2, 7, 4, 5};
int count = 11;
printf ("Count is %d.\n", count); should be 11.
printArray (array, count); should be array
delete_element (array, &count, 5, 0); // takes out 2 elements
printf ("Count is %d.\n", count); should be 9.
printArray (array, count); should be array without 5s
delete_element (array, &count, 3, 1); // takes out 3 elements. Leaves behind the first 3.
printf ("Count is %d.\n", count); should be 6
printArray (array, count); should be array without 5s or all but the first 3.
return 0;
}
int delete_elemet(int a[], int *n, int item, int loc)
{
// You do this part.
}
I'm having a pretty hard time with modifying the code you have however, so this is the best help I can offer. Try using the code that I have, of course inserting your own code for the delete_element function, and just kinda keep working at it untill it gets right.