Jump to content
  • Advertisement

Archived

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

hello_there

please help me!!

This topic is 5968 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok i can load number from a file into an array by loading every number seperatly. is there a way to load the whole thing in a few lines of code? i hope that makes sence

Share this post


Link to post
Share on other sites
Advertisement
Well depends how the file is stored (binary or text) but either way is easy enough. You just need to loop through the file loading each number as you find it (either in binary loading each number one after each other, or in text where you can load the number up until you reach a ''/0'', say). If you only have these numbers in the file then you can check at the start of each loop and exit when you have reached the end of the file, if you store other things in the same file then have a number at the start telling you how many numbers you have to load up and then loop that many times through the file.

void LoadIntoArray(int* Array)
{
ifstream fin("Filename.num");
int NumberToLoadIn = 0;
fin.read((char*)&NumberToLoadIn,sizeof(int));

if(Array)
delete Array;

if(NumberToLoadIn > 0)
{
Array = new int[NumberToLoadIn];
int Count = 0;

while(NumberToLoadIn > 0)
{
fin.read((char*)&Array[Count],sizeof(int));
count++;
}
}
else
{
Array = NULL;
}

fin.close();
}

Actually the loading into array line might be wrong, cant remember if you need the & or not, Im v tired, but that should work well enough (might want to create a new array in the func then return the address instead but either way)


Ballistic Programs

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!