Length of array (C) [migrated]
- by physics
I have an array of 10 elements. This array stocks some informations but last information is ended by an symbol "END" (which is -1).
for exemple:
array[0] = 1;
array[1] = 1;
array[2] = 1;
array[3] = 1;
array[4] = 1;
array[5] = 1;
array[6] = END;
So in this case the length is 7 instead of 10.
Here is my algorithm:
for (i = 0; (i < 10)
&& (array[i] != END); i++)
{
;
}
at the end i contains the length.
Is it correct or there is an other methode?