I'm unable to print the matrix that i build using the dynamic memory allocation in read function. Please guide me to pass the values from read to disp function.
I've tried passing pointer to pointer in single pointers but i have no idea about double pointers please help me.
int i; //global
struct pass{
int row,col,ele;
} a1;
void disp(int** , struct pass);
void read(int** , struct pass);
void disp(int** p, struct pass a)
{
printf("the triplet representation is\n"); //program stops here everytime
for(i=0;i<=a.ele;i++){
if(i==0){
printf("row\t column\t element\n");
printf("%d\t %d\t %d\n", p[i][0], p[i][1], p[i][2] );
}
else
printf("%d\t %d\t %d\n", p[i][0], p[i][1], p[i][2] );
}
}
void read(int** p, struct pass a)
{
int i;
printf("enter no. rows, columns, elements\n");
scanf("%d %d %d", &a.row, &a.col, &a.ele);
p=(int* *)malloc(sizeof(int*)*(a.ele+1));
for(i=0;i<=a.ele;i++)
p[i]=(int *)malloc(3*sizeof(int));
p[0][0]=a.row; p[0][1]=a.col; p[0][2]=a.ele;
printf("enter rows, columns, and elements\n");
for(i=1;i<=a.ele;i++){
scanf("%d %d %d", &p[i][0], &p[i][1], &p[i][2]);
}
}
int main()
{
int **p1;
read(p1, a1);
disp(p1,a1);
}
The expected output should be the sparse matrix to be printed but it refuses to do so after scanning the elements.