title: Splitting chars into array of char pointers
body: <p>I'm trying to split up a line of 80 characters of input into an array where each element points to a string of chars. Essentially, turn a char a[80] like "Hello world!" into a char* b[64] where b[0] points to "Hello" and b[1] points to "world!"</p>
  
  <p>Basically, what strsep() would allow me with the following code:</p>
  
  <pre><code>while((cmd-&gt;argv[argc++] = strsep(clPtr, WHITESPACE)) != NULL);
  </code></pre>
  
  <p>I would like to know how I would go about modifying this code:</p>
  
  <pre><code>int parse(char* comm, char** commarray) {
    int count = 0;
    char word[80] = "";
    char ch[2] = {' ', '\0'};
  
    if(strlen(comm) == 0) {
      commarray[0] = "NULL";
      return 0;
    }
  
    for(size_t i = 0; i &lt; strlen(comm); i++) {
      int c = int(comm[i]);
      if(!isspace(c)) {
        ch[0] = comm[i];
        strcat(word, ch);
        if(i == (strlen(comm) - 1)) {
          commarray[count] = word;
          cout &lt;&lt; commarray[count] &lt;&lt; endl;
          count++;
        }
      }
      else if(isspace(c) &amp;&amp; word != "") {
        commarray[count] = word;
        cout &lt;&lt; commarray[count] &lt;&lt; endl;
        word[0] = '\0';
        count++;
      }
    }
  
   return 1;
  }
  
  //main
  int main() {
    char command[80];
    char* args[64];
  
    while(true) {
      cout &lt;&lt; "order&gt;";
      cin.getline(command, 80);
  
      if(strcmp(command, "quit") == 0 || strcmp(command, "exit") == 0) {
        break;
      }
  
      parse(command, args);
  
      cout &lt;&lt; args[0] &lt;&lt; endl;
  
      if(strcmp(args[0], "quit") == 0 || strcmp(args[0], "exit") == 0) {
        break;
      }
  
      /*for(int i = 0; i &lt; 3; i++) {
          cout &lt;&lt; args[i] &lt;&lt; endl;
      }*/
    }
    return 0;
  }
  </code></pre>
  
  <p>The variable args in the main() does not display what the variable commarray does in parse(). Instead, I get gibberish. Why is this? I thought passing an array was by default a pass by reference? For commarray, I get the appropriate array of pointers to strings (I think). For args, I get nothing usable.</p>