0

Hi

I'm adapting some code I've written using 2d arrays (to represent matrices) to handle large arrays such that double matrix[][] goes to double **matrix and then I'm using malloc.

It seems to work fine for part of my program up to where I have to find the matrix transpose at which point it does something I don't understand. I've taken that bit of code out and run it by itself (included below), get the same problem and still can't work out why. Can anyone help??

Thanks

jbd

```
int find_transpose(int n, double **a, double **b)
{
int i,j;
for (i=0; i<n; i++)
{
for (j=0; j<n; j++)
b[i][j] = a[i][j];
}
for (i=0; i<n; i++)
{
for (j=0; j<n; j++)
b[i][j] = a[j][i];
}
}
int main (void)
{
int i, j, p=3;
double **in, **out;
in = malloc(p * sizeof(int *));
out = malloc(p * sizeof(int *));
for (i=0; i<p; i++){
in[i]= malloc(p * sizeof(int *));
out[i]= malloc(p * sizeof(int *));}
for (i=0; i<p; i++)
{
for (j=0; j<p; j++)
{in[i][j]= 10./(i+1);
printf("in[%i][%i] = %f\n", i, j, in[i][j]);
}
}
find_transpose(p, in, out);
for (i=0; i<p; i++)
{
for (j=0; j<p; j++)
printf("in[%i][%i] = %f\n", i, j, in[i][j]);
}
for (i=0; i<p; i++)
{
for (j=0; j<p; j++)
printf("out[%i][%i] = %f\n", i, j, out[i][j]);
}
return
```