Access Item in Nested Structure in C

前端 未结 2 735
执笔经年
执笔经年 2021-01-24 01:40

I try to access \"next\" in another structure, but failed although i have tried many ways.

Here is the nested structure:

struct list_head {
    struct l         


        
2条回答
  •  时光说笑
    2021-01-24 02:18

    list is not declared as a pointer, so you don't use the -> operator to get its members, you use the . operator:

    while (d->list.next != NULL) {
    }
    

    A different fix:

    typedef struct {
      char *key;
      char *value;
      struct list_head *list;
    }dict_entry;
    

    This way, your original code attempting to refer to next would compile.

提交回复
热议问题