Public Group

#### Archived

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

# Copying a 2D array into another array ?!?

This topic is 6028 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
Yes that is what I am trying to do with the above code but it doesnt work :<

##### Share on other sites
why don''t you use memcpy() ?

##### 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 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 ]
Thanks to Kylotan for the idea!

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632960
• Total Posts
3009476
• ### Who's Online (See full list)

There are no registered users currently online

×