Arthur
Arthur

Reputation: 86

question about syntax for structure in linked list

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

Answers (1)

kiran Biradar
kiran Biradar

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

Related Questions