Last active
December 22, 2015 02:09
-
-
Save Terminus-IMRC/6401222 to your computer and use it in GitHub Desktop.
Make dynamic 2-dimintional array which can be treated as dynamic 1-dimentional array.
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
/* Make sure that TYPE is defined. */ | |
#include <assert.h> | |
/* Make array[M][N] and array_1dim[M*N]. */ | |
void make_proper_array(int M, int N, TYPE** ret_array, TYPE* ret_array_1dim); | |
void make_proper_array(int M, int N, TYPE** ret_array, TYPE* ret_array_1dim) | |
{ | |
int i; | |
TYPE* array_1dim; | |
TYPE** array; | |
array=(TYPE**)malloc(sizeof(TYPE*)*M); | |
assert(array); | |
array_1dim=(TYPE*)malloc(sizeof(TYPE)*M*N); | |
assert(array_1dim); | |
for(i=0; i<M; i++) | |
array[i]=array_1dim+i*N; | |
ret_array=array; | |
ret_array_1dim=array_1dim; | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment