
-----------------------------------
shoobyman
Thu Nov 06, 2008 7:11 pm

malloc help - segmentation fault
-----------------------------------
I have to make a program that takes an input matrix (in a 2D array) and output it's inverse.  The problem i have is allocating memory to the dynamic array.  And yes, it must be a dynamic array and it must use malloc to allocate the memory.  Please help, it's been KILLING me for the past couple days.  It compiles, but when i run it i get a segmentation fault.


int main (void)
{
        int size, i;
        printf ("Enter dimension of square matrix:");
        scanf ("%d", &size);
        double **entries = (double **)malloc(size*size*sizeof(double));            // HERE IS WHERE THE PROBLEM (probably) IS
        printf ("\nEnter the %d entries of the matrix:", size*size);
        for (i=0; i