I want to collect a 3-dimensional matrix using malloc
. There is also the matrix printing part but I did not include that.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,j,k,m,n,o;
float ***A;
printf("Input dimension for matrix(m,n,o)\n");
printf("Enter m : ");
scanf("%d",&m);
printf("Enter n : ");
scanf("%d",&n);
printf("Enter o : ");
scanf("%d",&o);
A = (float***)malloc(o*sizeof(float**));
for(i=0;i<o;i++){
A[i] = (float**)malloc(m*sizeof(float*));
for(j=0;j<m;j++){
A[i][j] = (float*)malloc(n*sizeof(float));
}
}
for(i=0;i<o;i++){
for(j=0;j<m;j++){
for(k<0;k<n;k++){
printf("Input number for (%d,%d,%d) : ",j+1,k+1,i+1);
scanf("%f",&A[i][j][k]);
}
}
}
return 0;
}
Program seems to be skipping to the end after I finish input m,n,o, so I cannot enter any value of matrix. I have to use malloc
because it was required for the task.
EDIT: everything that is wrong. m is for row,n is for column, and o is for a number of mXn matrix.