What I am doing wrong here for C99:
struct chess {
struct coordinate {
char piece;
int alive;
} pos[3];
}table[3] =
{
{
{'Q', (int)1},{'Q', (int)1},{'Q', (int)1},
{'B', (int)1},{'B', (int)1},{'B', (int)1},
{'K', (int)1},{'K', (int)1},{'K', (int)1},
}
};
It gives the error:
error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token
I wish to be able to access the data like having a struct within a struct that:
table[row].pos[column].piece
table[row].pos[column].alive
I tried several combinations, and none seems to work for this case. I have done previous struct hard coded initialization before that works, but not a struct within a struct as this time.
Any suggestions?
struct chess {
struct coordinate {
char piece;
int alive;
} pos[3];
} table[3] =
{
{
.pos = {{ .piece = 'Q', .alive = 1 },
{ .piece = 'Q', .alive = 1 },
{ .piece = 'Q', .alive = 1 }
}
},
{
.pos = {{ .piece = 'B', .alive = 1 },
{ .piece = 'B', .alive = 1 },
{ .piece = 'B', .alive = 1 }
}
},
{
.pos = {{ .piece = 'K', .alive = 1 },
{ .piece = 'K', .alive = 1 },
{ .piece = 'K', .alive = 1 }
}
}
};
It seems to work. Just be careful about the placement of your braces, and PLEASE try to understand what you are typing. This is how to read the answer :
Advices :