why doesnt this program print?
Posted
by
Alex
on Stack Overflow
See other posts from Stack Overflow
or by Alex
Published on 2012-10-22T18:10:56Z
Indexed on
2012/10/22
23:00 UTC
Read the original article
Hit count: 161
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 ?
}
© Stack Overflow or respective owner