Tuesday, July 28, 2009

How do you copy a 2d numeric array in c?

if the array is char, strcpy can be used


if it is float, double or int?


thanks a bunch guys ;)

How do you copy a 2d numeric array in c?
#define SIZE1 10


#define SIZE2 20





float a[SIZE1][SIZE2];


float b[SIZE1][SIZE2];





// assign values into a





for (int i = 0; i != SIZE1; ++i)


for (int j = 0; j != SIZE2; ++j)


b[i][j] = a[i][j];





Works for any type that uses operator =
Reply:You can try using memcpy assuming you know the size of the original elements. Failing that, element by element?

flower seeds

No comments:

Post a Comment