How to create pointer array by memory allocation?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nozone
    New Member
    • Oct 2006
    • 4

    How to create pointer array by memory allocation?

    Hi. I am new to the C language. I need to store the commands from input to a pointer array without any "[]"declaratio n. How to create an pointer array by memory allocation? I tried to use the following statement, but it did not work.

    static char **choice = (char **)calloc(NUMBE R_COMMAND,sizeo f(char **));

    I want to declare this array as private and use by all functions, so I use "static".
    Thanks
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Code:
    static char **choice = (char **)calloc(NUMBER_COMMAND,sizeof(char *));
    
    for(i=0; i<NUMBER_COMMAND; i++)
    {
        choice[i] = (char *)calloc(<CommandSize>,sizeof(char));
    }

    Comment

    Working...