title: Parsing words from string in C
body: <p>I'm trying to extract the words from a string in C and I'm getting unexpected results. I have print statements that seem to confirm my control flow, but printing the final array returns nothing.</p>
  
  <p>In the code below I'm parsing trying to parse <code>input</code>, which is the string <code>"Some stuff  \t to parse &amp;"</code>. I want to turn that string into <code>params[0] = "Some"; params[1] = "stuff"; params[2] = "to"; params[3] = "parse"; params[4] = "&amp;";</code></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;string.h&gt;
  #define MAX_PARAMS 10
  #define MAX_WORDS 100
  
  void parse(void);
  char* input = "Some stuff  \t to parse &amp;";
  char* params[MAX_PARAMS+1] = {NULL};
  
  int main(int argc, char *argv[]) {
      parse();
      // Prints nothing!
      for (int i = 0; i &lt;= MAX_PARAMS; i++) {
          puts(params[i]);
      }
  }
  
  void parse(void) {
      char buffer[MAX_WORDS];
      memset(buffer, 0, MAX_WORDS);
      int param = 0;
      int buff = 0;
      int i = 0;
      for (; i &lt; strlen(input); i++) {
          if (isspace(input[i]) &amp;&amp; *buffer) {
              printf("Buffer '%s' being added to params[%d]\n", buffer, param);
              params[param++] = buffer;
              memset(buffer, 0, MAX_WORDS);
              buff = 0;
              if (param == MAX_PARAMS) {
                  break;
              }
          }
          else if (!isspace(input[i])) {
              buffer[buff++] = input[i];
              printf("%c added to buffer\n", input[i]);
          }
      }
  
      if (param &lt; MAX_PARAMS &amp;&amp; strcmp(buffer, "")) {
          params[param] = buffer;
          printf("Buffer '%s' being added to params[%d]\n", buffer, param);
      }
  }
  </code></pre>