I would like to pass a double array to a function via a pointer. However, despite trying a lot of things suggested here, I always get a segmentation fault upon initialization. I feel that it is very simple code (I am new to C), yet I cannot find my mistake. The code is as follows:
double *tMatrix = (double *)malloc(N*sizeof(double));
int i;
for (i=0;i<N;i++)
{
tMatrix[i] = 0.0;
}
computeMatrix(tMatrix);
I get a segmentation fault on the first initialization of tMatrix, that is, when i=0. I want to use a pointer for the array tMatrix as I want to pass the matrix to the function computeMatrix.