简体   繁体   中英

C - Initializing an array using variables with set values

I'm trying to initialize an array using already defined variables, for extensibility reasons.

Here are the calls that I'm making:

int dung_width = 160;
int dung_height = 105;

char dungeon[dung_height][dung_width];

I'm getting the error that dungeon is variably modified at file scope. Is this even possible and is this the best way of doing it?

PS I'm just starting C programming.

Use like this they will not trouble you if they are constants:

#define dung_width  160
#define dung_height  105

char dungeon[dung_height][dung_width];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM