How to implement a 2-dimensional array of struct in C

Viewed 62195

I'm currently trying to understand how to implement a 2-dimensional array of struct in C. My code is crashing all the time and I'm really about to let it end like all my approaches getting firm to C: garbage. This is what I got:

typedef struct {
    int i;
} test;

test* t[20][20];
*t = (test*) malloc(sizeof(test) * 20 * 20);

My glorious error:

error: incompatible types when assigning to type ‘struct test *[20]’ from type ‘struct test *’

Do I have to allocate the memory seperately for every 2nd dimension? I'm getting nuts. It should be so simple. One day I will build a time-machine and magnetize some c-compiler-floppies...

5 Answers
Related