return first non zero value in array, replace with zero

Hey if I have an array is there any way to get a function to return the first non zero element then replace that element with a zero?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int function(int ARRAY, int SIZE_OF_ARRAY)
{
	int saveMe = 0;
	for(int i = 0; i < SIZE_OF_ARRAY; i++)
	{
		if(ARRAY[i] != 0)
		{
			saveMe = ARRAY[i];
			ARRAY[i] = 0;
			return saveMe;
		}
	}
}
	
Last edited on
Thank you for taking the time to help me out. That's actually exactly what I had but wasn't sure if it would loop through replacing all elements with 0 and only return the last element.
That's actually exactly what I had but wasn't sure if it would loop through replacing all elements with 0 and only return the last element.

Is this what you want??
no I'm making a black jack game so I need to be able to return the top card or first non zero element, then replace that top card with zero because it will no longer be in the deck.
If your question is solved, you should consider marking the post solved.
got it thanks again
Topic archived. No new replies allowed.