Jump to content
  • Advertisement

Archived

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

Da cobra

passing a dubble array to a function

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

how do you pass on a dubble array like this char array[2] [80] = {{"text 1"}, {"text2}} ; function_text(char) ; // <= I want to pass the whole array to this function and no pointers pls thanx in advance for any help...

Share this post


Link to post
Share on other sites
Advertisement



void FuntTakingA2DArray(char arr[2][80])
{
cout<< arr[0];
cout<< arr[1];
}

void main()
{
char arr[2][80]={{"text1"},{"text2"}};
FuntTakingA2DArray(arr);
}



the name of an array contains the base address of the array which we are passing to the function . As u mentioned no pointers happy!

Share this post


Link to post
Share on other sites
thanx for the quick answer but I forgot to say something :

what if I don''t know how big the array will be?

it could also be :

char array[2] [80] = {{"text 1"}, {"text2}, {"text 3"}} ;

again thanx in advance for any replies

Share this post


Link to post
Share on other sites
If you don''t know the sizes, you''ll have to use pointers. Or a language which is a little fancier about its array implementation, such as Java. Or perhaps some sort of library. Sorry, I don''t remember how to do it in C++, or C for that matter, offhand - I pretty much never had to deal with such arrays in my code.

In that last example, you''ll need to use [3][80] rather than [2][80], of course.

It''s spelled "double", and you''re talking about a 2-dimensional array, not a "double array" which one would normally understand to mean an array of doubles (double-precision floating-point values).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
if it''s an array of null terminated strings you could do this:

func(const char* array[], int size){
for(int i=0; i<size; i++){
cout << array;
}
}

or else i think you have to pass both dimensions to the function?

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!