• Advertisement

Archived

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

Copying a 2D array into another array ?!?

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

In order to increase the columns in a matrix (I call a 2D array a matrix) I am creating a temporary matrix called MTemp with the new column size. Then I copy the old matrix, MData, into MTemp. I then erase MData and point MData towards MTemp. The part I need help in is the copying of the old matrix into the temporary one, I tried this code:
    		
for (IType1 i = 0; i < (hibnd1 + 1 - lobnd1); ++i)
{
     for(IType2 j = 0; j < (hibnd2 + 1 - lobnd2); ++j)
     {
	MTemp[i][j]=MData[i][j];
     }
}    
Which can be found from line 118 to 124 in matrix.h, but it gave me errors (you basically have to run it to see what I mean) so ive "commented" it out. Basically I need to know why it gives me the error and what code changes you would suggest? You need these files if you want to test my source: http://binary.gamer.net.nz/stuff/asn/tstMatrx.cpp http://binary.gamer.net.nz/stuff/asn/MATRIX.H http://binary.gamer.net.nz/stuff/asn/ARRAY.H Atm im trying to get the function addCol() working (in matrix.h) then ill attempt addRow() and grow(), plz ignore the latter two functions. NB: hibnd1/2 and lobnd1/2 are the the lower and upper bounds for the row and columns in the matrix. [edited by - Aragorn992 on April 19, 2002 5:42:49 AM]

Share this post


Link to post
Share on other sites
Advertisement
for every [i,j] in your original matrix, move the data to teh same [i,j] in your new matrix. The new column never comes into question. I should think.*not downloading your source*

Share this post


Link to post
Share on other sites
I cant, the only part of matrix.h I can change is inside those three functions. Hence I cant have #include <string.h> hence I cant use memcpy() :<

Share this post


Link to post
Share on other sites

for (IType1 x = lobnd1; x < (hibnd1 + 1 - lobnd1); ++x)
{
for(IType2 y = lobnd2; y < (hibnd2 + 1 - lobnd2); ++y)
{
MTemp[x][y]=MData[x][y];
}
}


That''s the most obvious thing I can think of. And no, I will not download your code.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ ]
[ MS RTFM [MSDN] | SGI STL Docs | Boost ]
[ Google! | Asking Smart Questions | Jargon File ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites

  • Advertisement