簡體   English   中英

結構和指針

[英]Struct and pointer

我正在嘗試打印由指針指向的值,該指針本身也由指針指向。

我有2個結構

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;

如何打印指向的結構的哈希值?

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

編譯器告訴我“錯誤:在非結構或聯合中請求成員'哈希'”

我嘗試了其他方法,但沒有一個在Thx的幫助下

你要這個:

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

*police_arg.lhash給您一個l_hash ,它是指向s_l_hash的指針,然后您可以將其取消引用以獲取hash

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM