Jump to content
  • Advertisement

Archived

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

Poontardis

pointers and references

This topic is 6569 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

Hi, I''ve been coding all day and my head is going to explode. I seem to be stuck in a rut of stupidity, so can someone help me out with this simple request??? I have a function which requires two large arrays of data to perform part of its function. Depending on the arguments supplied, another function is called to initialise and fill the arrays with data. What''s the best way to get this data back from the other function so that I can use it? Both arrays of data will be generated in the same function so I can''t use return values and I''m getting confused by trying to reference pointers to arrays. I''m presently declaring: char *data1 = NULL; char *data2 = NULL; in the main function but am confused as to how I can pass these pointers into another function so that it can initialise and fill the arrays, return and allow me to use the data in the main function before freeing the memory in the main function. Cheers, for any replies.

Share this post


Link to post
Share on other sites
Advertisement
like this
declare them in main
init memory in main

    
void fillArrays(char*, char*);

int main()
{
const int size1 = whateverYouWant;
const int size2 = whateverYouWant;
char* data1 = new char[size1];
char* data2 = new char[size2];

fillArrays(data1, data2);

// do rest of your program here


delete [] data1;
delete [] data2;
}

void fillArrays(char* data1, char* data2)
{
// initialize your arrays

}

there ya go



"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

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!