Hi Geeks,
 i have declare Char *a type variable and i want to fill data in a[0][n], a[1][n], ... a[max][n]. below is my code snippet which i'm facing build error while initializing.
 I'm getting build error as ".....subscript requires array or pointer type  " 

    .........
            char *a;

            a = (char*)calloc(3,sizeof(int)+3);//trying to allocate for these a[0][5], a[1][5], a[2][5]

            for (int i = 0;i<3;i++)
                for (int j = 0; j<5;j++)
                    a[i][j] = 1;                
    ..........    
--
Thanks in advance.

Line 6 : It should be char **a ; As you want to declare 2D array.

Line 8 : As you want to make a 2D array the statement should be

a = (char**)calloc(3,sizeof(int*));

Now calloc-ating a[0][1] , a[0][2] etc.

for(i = 0; i < 3; ++i) 
{
    a[i] = (char*) calloc(5, sizeof(int));
} 

Now you can use a[3][5] normally.

Thanks for the quick reply.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.