R
Rob Thorpe
I have a set of data structures that are collected together in array.
This array is in turn packaged in a struct itself. The structs look
like this:-
struct index_entry_t
{
char *id;
char *description;
};
typedef struct index_entry_t index_entry_t;
struct index_t
{
int no_of_entries;
index_entry_t *table[];
};
typedef struct index_t index_t;
The member 'table' of index_t contains an array of pointers to
index_entry_t's.
The program then goes on to make a pointer to an index_t. The result
is shown below:-
_____________
i ------>|index_t |
|_____________|
|no_of_entries|
|_____________|
|table | _______ _____________
|____________--------->| ----------------->|index_entry_t|
|_______| |_____________|
| ----------> |id |
|_______| |_____________|
| ----------> |description |
|_______| |_____________|
| ... |
My problem is, I can't find the right syntax to access the members, ie
the index_entry_t's.
To me these seem the right ways:
(i->table[n])->id
or
*(i->table[n]).id
but they both give the error:
test_ind2.c:86: error: request for member `description' in something
not a structure or union
on my compiler (gcc).
What is wrong?
This array is in turn packaged in a struct itself. The structs look
like this:-
struct index_entry_t
{
char *id;
char *description;
};
typedef struct index_entry_t index_entry_t;
struct index_t
{
int no_of_entries;
index_entry_t *table[];
};
typedef struct index_t index_t;
The member 'table' of index_t contains an array of pointers to
index_entry_t's.
The program then goes on to make a pointer to an index_t. The result
is shown below:-
_____________
i ------>|index_t |
|_____________|
|no_of_entries|
|_____________|
|table | _______ _____________
|____________--------->| ----------------->|index_entry_t|
|_______| |_____________|
| ----------> |id |
|_______| |_____________|
| ----------> |description |
|_______| |_____________|
| ... |
My problem is, I can't find the right syntax to access the members, ie
the index_entry_t's.
To me these seem the right ways:
(i->table[n])->id
or
*(i->table[n]).id
but they both give the error:
test_ind2.c:86: error: request for member `description' in something
not a structure or union
on my compiler (gcc).
What is wrong?