Start by using two array indexes, both initially set at 0:
inp
and
outp
.
inp
is where you get a value from, and goes up by one each time round the loop.
outp
is where you copy values to, and does not go up each time round the loop.
The loop through the whole array, adding one to
inp
each time:
for (inp = 0; inp < n; inp++)
Inside the loop, compare the current element with the valeu you want to remove.
If it's the same, do nothing at all!
Otherwise, copy it to the output, and increment
outp
data[outp++] = data[inp];
After the loop, the number of elements left is in
outp
This works because you are removing items: so you are copying the items you want to keep into place in a "shorter version" of the same array!
Heck, I'll even give you the code:
for (inp = 0; inp < n; inp++)
{
if (data[inp] != removeThisValue)
{
data[outp++] = data[inp];
}
}
for (int i = 0; i < outp; i++)
{
printf("%d\n", data[i]);
}
Have a think about it, and see if you can work out exactly what it does.