double **matrix = NULL;
matrix = (double **)malloc(sizeof(double *) * N); // N is the size of the square matrix
for(int i=0; i<N; i++)
{
matrix[i] = (double *)malloc(sizeof(double)*N);
}
// Works good up to the next part
for(int i=0; i<N; i++)
{
for(int j=0; j<N; j++)
{
printf("Value: %f", matrix[i][j]);
}
}
I'm trying to create a two dimensional array of doubles by using the method above (create an array of pointers, and then each pointer gets an array of doubles). However, as soon as I try to print the first element matrix[0][0], I get a seg fault. I've seen some other posts that do almost the same thing, except I can't get mine to work.