double** makeit(int, int);
void showit(double**, int, int, int);
int main()
{
int i,j;
int x,y;
printf("x=");
scanf("%d",&x);
printf("y=");
scanf("%d",&y);
double (*mas2d)[x];
mas2d=makeit(x,y);
printf("%4.0f ir %4.0f \n",mas2d[0][0],mas2d[1][0]);
showit(&mas2d, x, y);
return 0;
}
double** makeit(int x, int y)
{
double (*masp)[x];
int i,j;
double skc;
masp= malloc((x*y)*sizeof(double));
skc=1;
for (i=0;i<x;i++)
{
for (j=0;j<y;j++)
{
masp[i][j]=skc;
skc++;
}
}
return masp;
}
void showit(double** mas[], int x, int y)
{
int i,j;
printf("%4.0f ir %4.0f \n",mas[0][0],mas[1][0]);
printf("x===%d",x);
for(i=0;i<x;i++)
{
printf("\n");
for(j=0;j<y;j++)
{
printf("%4.0f \n",mas[i][j]);
}
}
}
What I do
1. I dynamically allocate double array mas2d in function makeit.
2. I want to send that mas2d array pointer to function showit and print it there.
What's the problem
I can print mas2d array pointer from main function with no problems, but when I pass it to separate function showit, I just cant get it work...
I've been trying to send it as a 3D pointer and maybe 100 other ways with no luck at all.
showit(&mas2d, x, y);but you declare it like this =>>void showit(double**, int, int, int);, Why ?makeit()andshowit()?