char monsternivel1[][3][4] = {
{"Rat","Bat","Spider"},
{"Goblin","Orc","Drawf"},
{"Dragon","Lich","Banshee"},
{"Demon","Hydra","Giant Spider"}
};
It says :
> E:\Dungeon Crawler.c||In function 'rndMonster':| E:\Dungeon
> Crawler.c|10|warning: initializer-string for array of chars is too
> long [enabled by default]| E:\Dungeon Crawler.c|10|warning: (near
> initialization for 'monsternivel1[0][2]') [enabled by default]|
> E:\Dungeon Crawler.c|11|warning: initializer-string for array of chars
> is too long [enabled by default]| E:\Dungeon Crawler.c|11|warning:
> (near initialization for 'monsternivel1[1][0]') [enabled by default]|
> E:\Dungeon Crawler.c|11|warning: initializer-string for array of chars
> is too long [enabled by default]| E:\Dungeon Crawler.c|11|warning:
> (near initialization for 'monsternivel1[1][2]') [enabled by default]|
> E:\Dungeon Crawler.c|12|warning: initializer-string for array of chars
> is too long [enabled by default]| E:\Dungeon Crawler.c|12|warning:
> (near initialization for 'monsternivel1[2][0]') [enabled by default]|
> E:\Dungeon Crawler.c|12|warning: initializer-string for array of chars
> is too long [enabled by default]| E:\Dungeon Crawler.c|12|warning:
> (near initialization for 'monsternivel1[2][2]') [enabled by default]|
> E:\Dungeon Crawler.c|13|warning: initializer-string for array of chars
> is too long [enabled by default]| E:\Dungeon Crawler.c|13|warning:
> (near initialization for 'monsternivel1[3][0]') [enabled by default]|
> E:\Dungeon Crawler.c|13|warning: initializer-string for array of chars
> is too long [enabled by default]| E:\Dungeon Crawler.c|13|warning:
> (near initialization for 'monsternivel1[3][1]') [enabled by default]|
> E:\Dungeon Crawler.c|13|warning: initializer-string for array of chars
> is too long [enabled by default]| E:\Dungeon Crawler.c|13|warning:
> (near initialization for 'monsternivel1[3][2]') [enabled by default]|
I didn't understand 3d arrays of char, any ideas? The first [] should be variable, the second [] should be how many strings and the third should be the categories?
What you want to do it probably:
const char *monsternivel1[4][3] = {
{"Rat","Bat","Spider"},
{"Goblin","Orc","Drawf"},
{"Dragon","Lich","Banshee"},
{"Demon","Hydra","Giant Spider"}
};
It's still an two dimensional array with char*'s. Notice, that the order for an 2 dimensional array is [row][column]
and not [column][row]
,
If you want a 3D array, then the last dimension must be big enough for each string:
char monsternivel1[][3][13] = {
{ "Rat", "Bat", "Spider" },
{ "Goblin", "Orc", "Dwarf" },
{ "Dragon", "Lich", "Banshee" },
{ "Demon", "Hydra", "Giant Spider" },
};
Note: 'drawf' -> 'dwarf'.
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