Andy202 wrote:
Thanks I just tested this and it did not work. The size is always 1. Have I implemented it correct?
Nope :) Use it as follows:
#define ARRAY_SIZE(_Array) (sizeof(_Array) / sizeof(_Array[0])) // This is the answer
char *OPTIONS1_ENUMS[] = {"OPT_1", "OPT_2", "OPT_3", "OPT_4"};
char *OPTIONS2_ENUMS[] = {"OPT_1", "OPT_4"};
char *OPTIONS3_ENUMS[] = {"OPT_1234"};
void GetOptions(short enumValue, char** szOptions, int Size)
{
printf("Array Size = %d\n", Size);
}
int main()
{
// In the Main program call GetOptions() for 3 different sized arrays
GetOptions(1, OPTIONS1_ENUMS, ARRAY_SIZE(OPTIONS1_ENUMS));
GetOptions(2, OPTIONS2_ENUMS, ARRAY_SIZE(OPTIONS2_ENUMS));
GetOptions(3, OPTIONS3_ENUMS, ARRAY_SIZE(OPTIONS3_ENUMS));
}
BTW you should not call your arrays OPTIONSx_ENUMS: - as capitalized names are conventionnally reserved for C macros, and - they are not enums but C arrays of const char*. cheers, AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)