I'm trying to allocate a 3D array in C. As you can tell, it's to store image data, in the form Array[height][width][channel]; This is the code I have.
BYTE*** allocateImageArray(INT_32 width, INT_32 height, INT_32 channels) {
BYTE*** array;
INT_32 i, j;
array = malloc(height * sizeof(BYTE**));
for(i = 0; i < height; i++) {
array[i] = malloc(width * sizeof(BYTE*));
for(j = 0; j < channels; j++) {
array[i][j] = malloc(channels * sizeof(BYTE));
}
}
printf("Pixel Array Size: %d\n", sizeof(array));
return array;
}
It compiles fine. However, the array is always 8 at the end (Indicated by the sizeof). And when I try to access the array later in the code the program just crashes.
All answers are thanked in advanced.
EDIT: Forgot to include. I've worked out where the program crash occurs. It happens when I try to assign a value to one of the BYTES at the end of the array.