Reputation: 86
I have question about the syntax for a structure inside a chained list:
I have this chain list structure:
typedef struct s_list
{
void *content;
size_t content_size;
struct s_list *next;
} t_list;
I want to point void *content to this structure:
typedef struct s_minos
{
char **minos;
} t_minos;
but when I try to acces my char **minos like this:
printf("%s\n", head->content->singleminos->minos[i]);
I declared : s_minos *singleminos;
and I assigned : head->content = singleminos;
It doesnt work.
How should I acces my data properly?
Upvotes: 2
Views: 66
Reputation: 12732
change this
printf("%s\n", head->content->singleminos->minos[i]);
to
printf("%s\n", ((t_minos *)(head->content))->minos[i]);
or
t_minos * temp = head->content;
printf("%s\n", temp->minos[i]);
you need to cast the void pointer
to original type before de-referencing.
Upvotes: 5