• Advertisement

Archived

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

getting nr of rows and cols from a dynamic array.

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

Is it possible to get the nr of rows and cols from a dynamicaly created 2d array? I have a function that takes an arraypointer, myfunc(double arraypointer**), and within this function i want to know the nr of rows and cols so that I modify the right things. [edited by - KH on February 6, 2004 6:17:05 AM]

Share this post


Link to post
Share on other sites
Advertisement
well, your array** points to some type of object like an int or a char or a Thingamajig*, right? The thing itself doesn''t need to know where it is, just that it is.

The other stupid anser would be "use vectors." then you can just call size() and get the answer.

Share this post


Link to post
Share on other sites
There''s no built-in way to do this. One solution would be to add two function params that indicate the number of rows and columns. Another is to create a structure that contains the array and the number of rows/columns, then pass a pointer to that as the function param.

Share this post


Link to post
Share on other sites
maybe

int array[12][23];

int iNumRows = sizeof(array[0]) / (array[0][0]);
int iNumElements = sizeof(array) / (array[0][0]);
int iNumColumns = iNumElements / iNumRows;

.... just maybe....

Share this post


Link to post
Share on other sites
problem is, inside his function all he has is a pointer and sizeof will return the size of the pointer.

Share this post


Link to post
Share on other sites

  • Advertisement