Advertisement

Arrays of variable size

Started by May 23, 2001 07:21 PM
2 comments, last by Armed and Hammered 23 years, 8 months ago
Hey i want to load in my games map from a text file, its an old text rpg. Anyway, i planed to hold the map size at the top of the file but I can''t figure out how to set an array to a variable size, ie the mapsize thats carried in the variable at the top of the file. Any help will be greatly appreciated Cheers. Armed and Hammered
Simple way:
Assuming you ant an array of ints...
int* GameMap = (int*)malloc(sizeof(int) * MAP_SIZE_X * MAP_SIZE_Y);
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Advertisement
Don''t forget to free it when you''re done (look up free, delete, as well as new and malloc (already mentions)). Dynamic Allocation is key to programming a lot of things .

Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/
How about

int* gameMap = new int[numberOfColumns * numberOfRows];

This topic is closed to new replies.

Advertisement