This topic is now archived and is closed to further replies.


External Array

Recommended Posts

I’m building a simple array based tile engine. I want to have an outside source to hold my array (E.g. World Map File). If I remember correctly, one way of doing it is; putting the array in a binary file using MSVC, then loading it into memory in my main code. If someone could clear this up for me, and maybe give me a idea of what to do, it would be very much appreciated. Jess,

Share this post

Link to post
Share on other sites
Um... what I think you should do is have world maps. These would store details about your world in a binary, which would be read in by your game. You would have an array and use fopen(), fread(), fclose(), etc., to read in the stuff.

I''ll repeat myself. You store the data in a file, but load it into your array inside your program. For example:

FILE* pInput = fopen("yourfile.dat", "rb");
if (pInput == NULL)
// whoops, it didn''t work!

// load in your file using fread(), fgets(), fscanf(), etc


To create the file, you can use fwrite() and so on. See MSDN for details.

If you want to write your file, the parameter for fopen() is "wb+" (I think, if I remember rightly), meaning open in binary writing mode, and create the file if it doesn''t exist. See 2D Game thingy. This discusses all sorts of tile game issues, and probably does loading too - I haven''t checked.

Alistair Keys

"There are two kinds of people, those who finish what they start and so on."
-- Robert Byrne

Share this post

Link to post
Share on other sites