C Double Pointer to Structure

后端 未结 5 987
面向向阳花
面向向阳花 2020-12-14 17:19

I am trying to work out a double pointer to a structure in C and cannot figure out what is going wrong... The simple source is below:

typedef struct
{
    in         


        
5条回答
  •  庸人自扰
    2020-12-14 17:57

    You received a segfault because you did not allocate a struct.

    The value of data is garbage, so it is pointing to some place in memory that is not owned by your process, or is otherwise inaccessible.

    You need to first allocate an object of type mystruct. Here is a working example for you: http://ideone.com/XIdJ8

提交回复
热议问题