I realized that strlen() only works on arrays of characters. I need to find a way to get the length of an array such as:
The answer would obviously be 3.Code:int array[10]; array[0] = 1; array[1] = 1; array[2] = 1;
I came up with this cheat that works in most cases:
it works for the above example, but for cases like array[1] = 0; the for loop would terminate on array[1], causing the length to return as 1.Code:int length = 0; for (int x = 0; array[x]; ++x) { ++length; } return length;
What's a good way to find the length of any type of array?
Thanks in advance.
edit: Changing array[x]; to array[x] || array[x] == 0; won't work as there are a few ways my cheat can be disrupted.