Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy 2-dim array to another array

Status
Not open for further replies.

Denaeghel

Programmer
Apr 23, 2001
61
BE
How can I copy a 2-dim unsigned int array into another 2-dim unsigned int array?

Thx

Karel Denaeghel_k@hotmail.com
 
by using nested loop...,
#define R 10
#define C 10
...
...
unsigned int source[R][C];
unsigned int destination[r][c];
int i, j;
...
...
for(i = 0; i < R; i++)
for(j = 0; j < C; c++)
destination[j] = source[j];
...
...

 
Oké, but isn't there a function who can do that. I tried with memcpy but no result. karel.denaeghel@barco.com
 
memcpy should work... make sure they are the same size and type if using memcpy unless you are trying to do some type of conversion (i.e. ints to 8 bit values you could use a char array) HOwever if you

unsigned int dim2orig[3][3];
unsigned int dim2copy[3][3];

i would use memcpy as

memcpy(*dim2copy,*dim2orig,sizeof(dim2copy));


Matt
 
Oké, that works but the problem is over there that I copy the pointers. I need the values.

You can compare it with a copy-constructor.

Karel karel.denaeghel@barco.com
 
i am a bit confused... if you are just copying the pointers it does not make sence to me with the memcpy UNLESS you are using a function to do the copy. If you were passing the 2 2-d arrays to a function to perform this, dont use the sizeof and instead pass the size and use that instead.

Matt
 
The problem is that I receive information at high speed in communication. I can't use the nested loops because they are to slow. I must copy the information before I receive the new information.

That's why I use memcpy. It's fast, but I can only use it for 1-dim array.

karel.denaeghel@barco.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top