I've tried shifting elements backwards but it is not making the array completely empty.
for(i=pos;i<N-count;i++)
{
A[i]=A[i+1];
}
Actually, I've to test for a key value in an input array and if the key value is present in the array then I've to remove it from the array. The loop should be terminated when the array becomes empty. Here "count" represents the number of times before a key value was found and was removed. And, "pos" represents the position of the element to be removed. I think dynamic memory allocation may help but I've not learned it yet.
Adefined? IfAis a static array you cannot change its size so there will always be some value in every entry. In that sense you can't "delete" an entry. What you can do is set it to an "invalid" value or keep track of a count of how many of the entries are considered valid.I've to test for a key value in an input array and if the key value is present in the array then I've to remove it from the arraybut then you also say ` The loop should be terminated when the array becomes empty.` so which is it are you emptying the whole array or deleting one element? This link describes removing elements from an array: stackoverflow.com/questions/15821123/… & this link describes emptying an array: stackoverflow.com/questions/32398192/…Norcountrecords the number of elements currently stored in the array. So, after your loop is done, you need to do eitherN -= 1orcount -= 1. (Or, if as seems likely, you're actually deletingcountnumber of items at positionpos, it'd beN -= count, and you'd also wantA[i] = A[i+count]in the loop.)