I am trying to make some simple functions that does some operations on matrixes. But i can`t undestand why the following code is not working!. Can you please help me to understand what is wrong here and what should i do???
void create(int*** p, const int n)
{
*p = (int**)calloc(n, sizeof(int));
if(*p == NULL){
printf("Error1");
}
int i;
for(i = 0; i < n; i++){
(*(p[i]) = (int*)calloc(n, sizeof(int)));
if(*(p[i]) == NULL){
printf("Error2");
}
}
}
void initializeMatrix(int*** p, const int n)
{
int i, j;
for(i = 0; i < n; i++){
for(j = 0; j < n; j++){
scanf("%d", &((p[i][j])));
}
}
}
void show(const int** p, const int n)
{
int i, j;
for(i = 0; i < n; i++){
for(j = 0; j < n; j++){
printf("%d ", ((p)[i][j]));
}
printf("\n");
}
}
int main()
{
int** p = NULL;
create(&p, 2);
initializeMatrix(&p, 2);
show(p, 2);
return 0;
}