Created
June 5, 2022 00:05
-
-
Save mu8086/ec8127a8ed79126772356adc2d48d1d5 to your computer and use it in GitHub Desktop.
[C] 3dArray
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char ***char3dArray(int length, int width, int height) { | |
// ret[height][width][length] | |
char ***ret = (char ***) malloc(sizeof(char **) * height + sizeof(char *) * height * width + sizeof(char) * height * width * length); | |
char **first_row = (char **)(ret + height); | |
char *first = (char *)(first_row + height * width); | |
memset(first, 0, sizeof(char) * height * width * length); | |
for (int i=0, j, wl = width * length; i<height; ++i) { | |
ret[i] = first_row + i * width; | |
for (j=0; j<width; ++j) { | |
ret[i][j] = first + i * wl + j * length; | |
} | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment