Mark Löwe
Mark Löwe

Reputation: 582

Defining Arrays of type Struct

I've looked at several examples and none quite match my problem. I'm trying to define an array of struct, no biggie, but when I do this in Xcode using pure C, I get a "Expected Expression" error that's driving me nuts.

The Code is as follows:

struct myType {
    unsigned char varName1;
    unsigned char varName2;
    unsigned char varName3;
};

struct myType myArray[10];

myArray[0] = {1,2,3}; // doesn't work at all despite many docs that say it will
myArray[1].varName1 = 1; // throws "expected expression" error

What am I doing wrong? I've checked for hidden characters, etc., nothing. It's clean and not imported into Xcode.

Upvotes: 1

Views: 152

Answers (2)

Mario
Mario

Reputation: 66

myArray[0] = (struct myType) {1,2,3};

Upvotes: 3

amald
amald

Reputation: 346

myArray[0] = {1,2,3} missing

";"

myArray[0] = {1,2,3};

Upvotes: 0

Related Questions