Hi,
sizeof cannot help here.
The confusion arises because this is the one place that the use of an array is not converted into a pointer first. It is never possible, using sizeof, to find out how long an array a pointer points to is, you must have a genuine array name instead.
So i would advise a second table like AlexN suggested.
There is another tricky solution but there are many BUTs ^^
All Arrays must be allocated one after each other in memory and best #pragma 1
This Solution is NOT advised but works 100% ^^
#include <stdio.h>
//
#pragma(1)
typedef struct
{
char *szName;
int iDummyValue;
} FOO;
//
static const FOO foo1[]=
{
{ "foo 1 - row 1", 1 },
};
//
static const FOO foo2[]=
{
{ "foo 2 - row 1", 1 },
{ "foo 2 - row 2", 1 },
{ "foo 2 - row 3", 1 },
};
//
static const FOO foo3[]=
{
{ "foo 3 - row 1", 1 },
{ "foo 3 - row 2", 1 },
};
static const FOO endfoo[]=
{
{ NULL , 0 },
};
//
static const FOO *foos[] = { foo1, foo2, foo3, endfoo };
int main(void)
{
int iFoos = sizeof(foos)/sizeof(foos[0])-1;
printf("%d foos found.\n", iFoos);
for ( int i = 0; i < iFoos; i++ )
{
printf("foo %d has %d rows.\n", i+1,( foos[i+1] - foos ) );
}
return 0;
}