Why is this function not working?

I'm trying to find first non zero element in an array then replace the zero with nextCard. it just will not work. Any thought?

1
2
3
4
5
6
7
8
9
10
void addToHand(int hand[], int cardToAdd)
{
int i=0;

	while (hand[i]!=0)
	{
		i++;
	}
	hand[i]=cardToAdd;
}
What do you mean that it's not working? Does it crash? Does it leave the first zero element unchanged?

Not sure what nextCard is. Are you sure the arguments that you pass to the functions are correct? Does the array have a zero element?
Put your whole code or at least we can see how you declare the array you passed as parameter when you call addToHand()
Topic archived. No new replies allowed.