I have declared the struct
struct wnode {
char *word;
int lines[MAXLINES];
struct wnode *left;
struct wnode *right;
};
and the pointer
struct wnode *p;
The pointer is passed to a function.
In that function, I first allocate memory for the pointer with malloc. Then I want to initialize the struct member lines to zero zero out the struct member lines.
An array initialization method will not work as it is interpreted as assignment:
p->lines[MAXLINES] = {0};
The compiler throws the error:
error: expected expression before '{' token
In the end, I'm just using a for loop to zero out the lines array:
for (i = 0; i < MAXLINES; i++)
p->lines[i] = 0;
Is there a better way?