forloop doesn't take define?
Hello,
I seem to be mixed up in how to reference an item of an array which is a
struct's member AND an array of this struct is done and its address of the
latter is assigned to another member of a second struct. I don't know if I am
saying this right ! If someone can tell me how we identify this in
proffessional coding lingo, I would be very greatfull. Thankyou in advance!
Anyways, I will display the code. It is to be noted the code does not
compile and I get the following error:
c:\_DTS_PROGRAMMING\C_PROGRAMMING\c\ARRAYSIZES\test.cpp(29): error C2296:
'/' : illegal, left operand has type 'long [5]'
Basically, I want the size of an array and I would like to itterate a for
loop based on this size value of this array. I don't know what I am doing
wrong. Can someone help me fix this error.
Here's the code:
===============================
#include <stdio.h>
#include <stdlib.h>
typedef struct menusColl{
long SFI[5];
}MC;
typedef struct menus {
struct menusColl *pCOLL;
} MENUS;
MENUS* config (MENUS *obj_MENUS)
{
static MC MENUSCOLL1[] = {0, 5, 10, 400, 405};
obj_MENUS = (MENUS*) malloc (sizeof (struct menus));
obj_MENUS->pCOLL = MENUSCOLL1;
return obj_MENUS;
}
void d(MENUS *obj_M)
{
#define SX (sizeof((obj_M->pCOLL[0].SFI) / (sizeof(obj_M->pCOLL[0].SFI[0]))))
long x;
for(x=0; x < SX; x++) // <<< ERROR POINTS HERE
{}
}
int main ()
{
MENUS *obj_MENUS = NULL;
int x;
obj_MENUS = config(obj_MENUS);
d(obj_MENUS);
free(obj_MENUS);
return 0;
}
==============================
All help is sincerely appreciated. Thanks in advance.
--
Best regards
Roberto