结构和指针

问题描述 投票:0回答:1

我正在尝试打印由指针指向的指针指向的值。

我有两个结构

typedef struct s_thread_police
{
    l_hash *lhash;
    // other stuff for thread purpose
} thread_police_arg;

typedef struct s_l_hash
{
    struct s_l_hash* next;
    char* hash;
} *l_hash;

如何打印我指向的struct的哈希?

police_arg.lhash = &lhash;
printf("%s\n", *(police_arg.lhash)->hash);

编译器告诉我“错误:请求成员'哈希'的东西不是结构或联合”

我尝试了其他方式,但他们都没有为你的帮助工作

c pointers struct
1个回答
0
投票

你要这个:

printf("%s\n", (*police_arg.lhash)->hash);

*police_arg.lhash给你一个l_hash,这是一个指向s_l_hash的指针,然后你取消引用hash

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.