You are doing it wrong. I will try to explain using a small code example. The explanation is in the code comments:
int array[100]; int size = sizeof(array) / sizeof(array[0]);
As you can see from the above code, you should not use sizeof to find out how many elements are in the array. The right way to do this is to have one (or two) variables to keep track of the size.
const int MAXSIZE 100; int array[MAXSIZE]; int size = 0;
source share