why doesnt this program print?
- by Alex
What I'm trying to do is to print my two-dimensional array but i'm
lost.
The first function is running perfect, the problem is the second or maybe the way I'm
passing it to the "Print" function.
#include <stdio.h>
#include <stdlib.h>
#define ROW 2
#define COL 2
//Memory allocation and values input
void func(int **arr)
{
int i, j;
arr = (int**)calloc(ROW,sizeof(int*));
for(i=0; i < ROW; i++)
arr[i] = (int*)calloc(COL,sizeof(int));
printf("Input: \n");
for(i=0; i<ROW; i++)
for(j=0; j<COL; j++)
scanf_s("%d", &arr[i][j]);
}
//This is where the problem begins or maybe it's in the main
void print(int **arr)
{
int i, j;
for(i=0; i<ROW; i++)
{
for(j=0; j<COL; j++)
printf("%5d", arr[i][j]);
printf("\n");
}
}
void main()
{
int *arr;
func(&arr);
print(&arr); //maybe I'm not passing the arr right ?
}