J
Joseph
I am trying to create a function that allocates memory for the matrix
through a function; like the code below. However, this does not seem to
work since I believe that the scope of the memory allocation only lasts
within the create function. Is there anyway around this? Thanx in
advance. I also DON'T want to declare int **matrix globally.
int main(void)
{
int **matrix;
create(matrix);
}
void create(int **matrix)
{ /*allocating mem for 2 by 3 int matrix*/
matrix = (int **)malloc(2*sizeof(int *));
matrix[0] = (int *)malloc(3*sizeof(int));
matrix[1] = (int *)malloc(3*sizeof(int));
}
through a function; like the code below. However, this does not seem to
work since I believe that the scope of the memory allocation only lasts
within the create function. Is there anyway around this? Thanx in
advance. I also DON'T want to declare int **matrix globally.
int main(void)
{
int **matrix;
create(matrix);
}
void create(int **matrix)
{ /*allocating mem for 2 by 3 int matrix*/
matrix = (int **)malloc(2*sizeof(int *));
matrix[0] = (int *)malloc(3*sizeof(int));
matrix[1] = (int *)malloc(3*sizeof(int));
}