hello i have some a problem with malloc, here is my code:
int add(int m,int n)
{
int **pina, **pinb, **pinc;
int c=m*n, i=0, j=0;
pina=NULL;
pinb=NULL;
pinc=NULL;
free(pina);
free(pinb);
free(pinc);
pina = (int **) malloc (sizeof(int *) *c);
pinb = (int **) malloc (c* sizeof(int *));
pinc = (int **) malloc (c* sizeof(int *));
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
pina[i][j]= NULL;
pinb[i][j]= NULL;
pinc[i][j]= NULL;
}
}
printf("Give elements for A\n");
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
scanf("%d",&pina[i][j]);
}
}
printf("Give elements for B\n");
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
scanf("%d",&pinb[i][j]);
}
}
printf("\n");
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
printf("%d ",pina[i][j]);
}
printf("\n");
}
printf("\n");
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
printf("%d ",pinb[i][j]);
}
printf("\n");
}
free(pina);
free(pinb);
free(pinc);
}
I just scanf array A and Array B from keyboart and then i print them.
the problem is that when i print array B is the same one with A.
I think tha somehow malloc doesn't work.
Any help plz?