Advertisement

Copying a 2D array into another array ?!?

Started by April 19, 2002 04:38 AM
4 comments, last by Aragorn992 22 years, 8 months ago
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]
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*
Advertisement
Yes that is what I am trying to do with the above code but it doesnt work :<
why don''t you use memcpy() ?

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() :<
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!

This topic is closed to new replies.

Advertisement