I have written a function, which binary copies one array of structures to another. The problem is that it doesn't work properly, and I don't know why. Everything seems to be OK to me.
- pixel is a structure with 3 unsigned char's, sizeof(pixel) = 3,
- pixarr1 is a pointer to two dimensional DYNAMIC array [8][2],
- pixarr2 is a pointer to two dimensional DYNAMIC array [8][n]. For example, n = 8, thats not important.
I need to do something like this:
for(int i=0; i<8; i++) {
for(int y=0; y<2; y++) {
arr2[i][y] = arr1[i][y];
}
}
But i want to do it "binary". Like this:
void copyStruct(pixel*** pixarr1, int startline, int height, pixel*** pixarr2) {
pixel** arr1 = *pixarr1;
pixel** arr2 = *pixarr2;
unsigned char buffer[16];
int sizeofstruct = height*3*8;
int padding;
for(int i=0; i<=sizeofstruct; i+=16) {
if ( i+16 > sizeofstruct) {
padding = sizeofstruct-i;
memcpy(buffer, arr1+i, padding);
memcpy(arr2+(startline*8)+i, buffer, padding);
} else {
memcpy(buffer, arr1+i, 16);
memcpy(arr2+(startline*8)+i, buffer, 16);
}
}
}
What mistake am I making?
PS. sorry for that problems with source, this editor is ..
PPS. Please dont focus on use of pointers. I must use them. If I print pointers outside and inside the function, I see the same address, so it's good (in my logic).