-1

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
 };
Stargateur
  • 24,473
  • 8
  • 65
  • 91

1 Answers1

2

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 };
}
Stephan Lechner
  • 34,891
  • 4
  • 35
  • 58