I have made an array like this but then it keeps saying I had too many initializers. How can I fix this error?
int people[6][9] = {{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0}};
too many initializers. The number of initializers exceeds the number of objects to be initialized.
An initializer-list is ill-formed if the number of initializer-clauses exceeds the number of members or elements to initialize.
Initializer. In C/C99/C++, an initializer is an optional part of a declarator. It consists of the '=' character followed by an expression or a comma-separated list of expressions placed in curly brackets (braces).
The issue here is that you have the rows/columns indices swapped in the array declaration part, and thus the compiler is confused.
Normally when declaring a multi-dimensional array, first index is for rows, second is for columns.
This form should fix it:
int people[9][6] = {{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0}};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With