Error declaring a matrix

Asked

Viewed 43 times

1

I made a matrix[day][time], but I get error when initializing it.

I get that mistake and I don’t know how to fix it

error: expected ':', ',', ';', '}' or 'attribute' before '=' token

The code is like this:

struct horario{
    char M[8][40] = {{"X 8 9 10 11 12 13 14 15 16 17 18 19 20"},
                    {"S"},
                    {"T"},
                    {"Q"},
                    {"Q"},
                    {"S"},
                    {"S"},
                    {"D"}   };
};

1 answer

1


Cannot initialize with value in structure declaration. You can do this in variable definition:

int main(void) {
    struct horario {
        char M[8][40];
    };
    struct horario hora = { .M = {
        {"X 8 9 10 11 12 13 14 15 16 17 18 19 20"},
        {"S"},
        {"T"},
        {"Q"},
        {"Q"},
        {"S"},
        {"S"},
        {"D"}}};
}

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.