I have written the following code to dynamically allocate a two-dimensional array, loop through it to take user inputs, store them and finally return it.
int **input(const int row, const int column, const char *message)
{
printf("\n%s \n", *message);
int **matrix = (int **)calloc(row, sizeof(int *));
for (int a = 0; a < column; a++)
*(matrix + a) = (int *)calloc(column, sizeof(int));
/* scanf */
for (int r = 0; r < row; r++)
{
for (int c = 0; c < column; c++)
{
printf("E[%d][%d]: ", r + 1, c + 1);
scanf("%d", ((matrix + r) + c));
}
}
/* endscanf */
return matrix;
}
When I invoke this function, the program exits without any notice or warning. It also doesn't show any log.
int **test = input(2, 2, "Test:");
What am I doing wrong here?