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


I am currently trying to understand how to implement a 2-dimensional array of structures in C. My code is all the time and I'm actually doing it to end it like all of my perspectives, such as: Garbage This is what I have found:

  Typefiff straight {int i; } testing; Trial * T [20] [20]; * T = (test *) maulok (size (test) * 20 * 20); My Majesty error:  

Error: Incompatible type when typing 'Structure Test * [20]' to type 'Structure Test *' Specify

Do I have to allocate memory to every other dimension? I'm going crazy it should be so simple one day I will make time machine and some c-compiler-floppies will be magnetized ...

It should be sufficient:

  typingfile structure {int i; } testing; Test t [20] [20];  

This will declare a 2-dimensional array of 20x20 size test . There is no need to use Malloc.

If you want to dynamically allocate your array, you can do this:

  // Course in a test course ** T = (test **) malloc (20 * size (test *)); For (i = 0; i & lt; 20; ++ i) t [i] = (test *) malloc (20 * size (test));  

Comments