- Sep 10, 2005
- 7,458
- 1
- 76
If I am using malloc in a function to allocate space to 2-d array (double ptr), how come main does not see this? How do I make this work T_T
o wow, wuts up with attach code?
#include <stdio.h>
#include <stdlib.h>
void alloc_maze(int**, int, int);
int main(void)
{
int row, col; int i, j;
int **maze;
alloc_maze(&maze, row, col);
return(0);
}
void alloc_maze(int **maze, int row, int col)
{
int i;
**maze = malloc(row * sizeof(int *));
for (i = 0; i < row; i++){
*maze = malloc(col * sizeof(int));
}
}
o wow, wuts up with attach code?
#include <stdio.h>
#include <stdlib.h>
void alloc_maze(int**, int, int);
int main(void)
{
int row, col; int i, j;
int **maze;
alloc_maze(&maze, row, col);
return(0);
}
void alloc_maze(int **maze, int row, int col)
{
int i;
**maze = malloc(row * sizeof(int *));
for (i = 0; i < row; i++){
*maze = malloc(col * sizeof(int));
}
}