Using -> to access property of struct but getting compiler error telling me to use ->?

前端 未结 1 690
花落未央
花落未央 2021-01-23 05:54

This is my first time using C, it\'s not gentle. I\'m trying to do something familiar to me in other languages, but this pointer issue is hitting me hard.

I\'m given the

1条回答
  •  既然无缘
    2021-01-23 06:16

    firstRecord->name is equivalent to (*firstRecord).name. It dereferences a pointer and then looks for a member.

    But firstRecord is a pointer to pointer to struct, not a pointer to struct, so you need to dereference twice. Use either of (**firstRecord).name or (*firstRecord)->name.

    0 讨论(0)
提交回复
热议问题