Note that there are some explanatory texts on larger screens.

plurals
  1. POreturn an array of pointer, return type?
    primarykey
    data
    text
    <p>I have a function..</p> <pre><code>char ** getCommand() { char *commandArray[BUFSIZ]; //declaring an array of char pointers // i m doing things to array return commandArray; } </code></pre> <p>I am getting an error saying "conflicting types". what is the type of commandArray? It is a pointer to a pointer right?</p> <p>I tried char *getcommand()...that didn't work either. I am calling this function in main so I have delcared..</p> <pre><code>main() { char *commands; commands = getCommand(); //this didn't work // So I redeclared... char *commands[BUFSIZ]; commands = getCommand(); //this didn't work either. } </code></pre> <p>Whats going on? I have never worked w/ array of pointers before... someone simplify the problem...and give me some kind of hint pls..</p> <p><strong>EDIT</strong></p> <p>Ok thanks for the suggestions...didn't work...</p> <p>I am pasting the code...suggested changes reflected..getting same error, saying the getCommand has conflicting error types.</p> <pre><code>char **getCommand() { int command_num; char input[BUFSIZ]; char **commandArray; command_num = 0; commandArray = (char**) malloc (BUFSIZ * sizeof(char)); fgets(input,sizeof(input),stdin); commandArray[command_num] = strtok(input, " "); /*breaks a string of commands into tokens*/ while (commandArray[command_num]!= NULL) { printf ("%s\n", commandArray[command_num]); command_num++; commandArray[command_num] = strtok (NULL, " "); } commandArray[command_num] = NULL; /*very imp - adds null in the last position*/ return commandArray; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload