Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

making a char array error

Tags:

c++

in a larger code i have this code:

#define N 10
..
..
..
char Map [N][N] =              {"##########",
                                "#@       #",
                                "#        #",
                                "#        #",
                                "#        #",
                                "#        #",
                                "#        #",
                                "#        #",
                                "#        #",
                                "##########"};

when i try to compile and run it form Code bloke i gives me the error

F:\C++\Maze\main.cpp|25|warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]|

any idea what i did wrong in this simple code?

like image 618
JohnnyF Avatar asked Jun 05 '26 11:06

JohnnyF


1 Answers

The length of each row in your example is 10+1=11 (remember the null terminator for string needs space to allocate). So:

#define N 10
#define M 11
char Map [N][M] =              {"##########",
                                "#@       #",
                                "#        #",
                                "#        #",
                                "#        #",
                                "#        #",
                                "#        #",
                                "#        #",
                                "#        #",
                                "##########"};
like image 76
Miguel Prz Avatar answered Jun 07 '26 00:06

Miguel Prz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!