I’ve forgotten how count a double dimension C array because I don’t understand why this code return me a count of 12 instead of 6.
// My tab
static NSString *kStringTag[][2] = {
{@"string1", @"1"},
{@"string2", @"1"},
{@"string3", @"0"},
{@"string4", @"0"},
{@"string5", @"1"},
{@"string6", @"1"},
{nil, nil}
};
// My C func
unsigned int tablen(void **tab)
{
unsigned int i = 0;
while (tab[i] != nil)
i++;
return i;
}
- (void)viewDidLoad
{
NSLog(@"%d", tablen((void **)kStringTab));
}
Your code is not C.
If it were C,
tabwould be an array of array of pointers to NSStrings (whatever that is).In C an array of arrays of pointers to NSStrings is not necessarily compatible with a pointer to pointer to void … so remove the casts and get the types correct.
In C, this works …
Suggestion: increase the warning level of your compiler and mind the warnings.
Edit: new generic version
You can see it running at ideone.