Here is the code I used when i try to initialize the struct L:
typedef struct {
int data[20];
int length;
} SqList;
SqList L;
L = {
{1,2,3,4,5},
5
};
Here is the code I used when i try to initialize the struct L:
typedef struct {
int data[20];
int length;
} SqList;
SqList L;
L = {
{1,2,3,4,5},
5
};
You are not initializing but assigning, because declaration of L
and assigning a value are two separate statements in your code.
Write
SqList L = {
{1,2,3,4,5},
5
};
and it should work.
You can overwrite this initial value later, but note that you need to assign an SqList-object then, and the assignment must happen in the context of a function:
int main() {
L = (SqList){ {1,2,3,4,5}, 5 };
}