Art*_*hur 2 c struct linked-list
我对链式列表中的结构的语法有疑问:
我有这个链表结构:
typedef struct s_list
{
void *content;
size_t content_size;
struct s_list *next;
} t_list;
Run Code Online (Sandbox Code Playgroud)
我想将void*内容指向此结构:
typedef struct s_minos
{
char **minos;
} t_minos;
Run Code Online (Sandbox Code Playgroud)
但是当我试图像这样访问我的char**minos时:
printf("%s\n", head->content->singleminos->minos[i]);
Run Code Online (Sandbox Code Playgroud)
我宣布:s_minos *singleminos;
我分配了:head->content = singleminos;
它不起作用.
我该如何正确访问我的数据?
改变这一点
printf("%s\n", head->content->singleminos->minos[i]);
Run Code Online (Sandbox Code Playgroud)
至
printf("%s\n", ((t_minos *)(head->content))->minos[i]);
Run Code Online (Sandbox Code Playgroud)
要么
t_minos * temp = head->content;
printf("%s\n", temp->minos[i]);
Run Code Online (Sandbox Code Playgroud)
您需要void pointer在取消引用之前将其转换为原始类型.