allocating mem for an array

This is a discussion on allocating mem for an array within the Linux Programming forums, part of the Platform Specific Boards category; I'm curious as to how I would allocate memory as needed for a multideminsional array? ex:
Code:
char command_names[*][20]; //improper, ...

>char command_names[*][20]; //improper, yes I know
Is totally wrong in the declaration itself. If you want to declare 20 pointers to type 'char *', then this is the way you do it:

Code:

char *command_name[20];

Now that you declared 20 pointers, they are randomly pointing to some memory location in you physical RAM. You need to make them point to your program's address space, so you use malloc() to allocate memory in your address space, and make these pointers point to the returned allocated space by. To allocate, you do: