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


pointers and references

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
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