how would i use calloc to allocate memory for a 2-D array outside of main. in main are: int rows, int cols, and int **array. the values for rows and cols were inputed by the user in a separate function also outside of main. so far i have:
int function (int *rows, int *cols, int ***array)
{
int i;
if(!(*array = (int **) calloc (*rows, sizeof (int *))))
{
printf("error message"
return 1;
for (i = 0; i < *rows; i++)
if(!(*(array + i) = (int **) calloc (*cols, sizeof (int *))))
{
printf("error message"
return 1;
}
}
return 0;
}
int function (int *rows, int *cols, int ***array)
{
int i;
if(!(*array = (int **) calloc (*rows, sizeof (int *))))
{
printf("error message"
return 1;
for (i = 0; i < *rows; i++)
if(!(*(array + i) = (int **) calloc (*cols, sizeof (int *))))
{
printf("error message"
return 1;
}
}
return 0;
}