I have an array which is 3d. I used to initialise it by just
It's for storing pixel colors in gtk. If I want to malloc the size because it may be variable, how can I do it?
I tried this, but it didn't work.
GLubyte *** array;
array = malloc(sizeof(GLubyte) * 256);
for(i = 0; i < 256; i++)
array[i] = malloc(sizeof(GLubyte) * 512)
for(j = 0; j < 512; j++)
array[i][j] = malloc(sizeof(GLubyte) * 3);
somehow when I tried accessing it, halfway, it'll have segmentation fault or something.
But if I initialise it with