n-dimension dynamic allocated array with malloc()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

What's wrong with the following code:

[fabio@localhost projects]$ cat poc.c ; gcc poc.c ; ./a.out
main()
{
        #define A 100
        #define B 100
        #define C 100
        #define D 100
        int i,j,k,l;
        double ****array;
        //srand( (unsigned) time(0x0));
        for(i=0;i< A; i++)
        {
                array = malloc(A * sizeof(double));
        }
        for(i=0;i< B; i++)
        {
                array[i]=malloc(B * sizeof(double));
        }
        for(i=0;i<C;i++)
        {
                array[i][i]=malloc(C * sizeof(double));
        }
        for(i=0;i<D;i++)
        {
                array[i][i][i]=malloc(D * sizeof(double));
        }

        for(i=0;i<A;i++)
                for(j=0;j<B;j++)
                        for(k=0;k<C;k++)
                                for(l=0;l<D;l++)
                                        array[i][j][k][l] = (double) 0;

}



Segmentation fault
[fabio@localhost projects]$


Thanks for any helpy,



---
Fabio Andres Miranda
Ingenieria de sistemas informaticos
Universidad Latina - Costa Rica

-
: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux