Writing init function for C struct

后端 未结 2 390
攒了一身酷
攒了一身酷 2021-01-21 18:02

So this is my struct in a header file:

struct _Variable {
    char *variableName;
    char *arrayOfElements;
    int32_t address;
};
typedef struct _Variable Var         


        
2条回答
  •  感情败类
    2021-01-21 18:27

    You should pass &variable1 to your method. Operator & will take the address of your struct and that is what you need to assign to the pointer on variable.

    Use:

    Variable var1;
    

    And then call the method:

    initVariable(&var1, "variable1", "1, 2, 3", 4);
    

提交回复
热议问题