Error declaring an array

1

I made an array [day] [time], but I get an error initializing it.

I get this error and I do not know how to fix it

  

error : attribute

The code looks 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"}   };
};
    
asked by anonymous 23.07.2017 / 18:54

1 answer

1

Can not initialize with value in structure declaration. You can do this in the 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"}}};
}

See running on ideone . And no Coding Ground . Also I put it in GitHub for future reference .

    
23.07.2017 / 19:15