title: Why is strtok() splitting words and limiting words to 7 characters in C?
body: <p>I have been searching everywhere for the past two days and cannot figure this out. Here is a small sample of the output:</p>
  
  <p>It should read "and find a pleasure":</p>
  
  <p>and</p>
  
  <p>f</p>
  
  <p>ind</p>
  
  <p>a</p>
  
  <p>p</p>
  
  <p>leasure</p>
  
  <p>================</p>
  
  <p>length   count</p>
  
  <p>================</p>
  
  <p>1   9054</p>
  
  <p>2   10102</p>
  
  <p>3   9336</p>
  
  <p>4   5944</p>
  
  <p>5   3311</p>
  
  <p>6   1656</p>
  
  <p>7   1292</p>
  
  <p>================</p>
  
  <p>average 2.86</p>
  
  <p>================</p>
  
  <p>Below is the code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include&lt;string.h&gt;
  
  #define DELIM " ,.;:'\"&amp;!? -_\n\t\0"
  
  int process(int *count, char *buffer);
  int printOut(int *count);
  
  int main() {
      char *buffer = (char *) calloc(1, 50*sizeof(char*));
      int *count =(int*) calloc(50, 50*sizeof(long));
  
      while (fgets(buffer, sizeof buffer, stdin)) {
          process(count, buffer);
      }
  
      printOut(count);
      free(count);
      return 0;
  }
  
  int process(int *count, char *buffer) {
      int word_len=0, i;
      char *pch;
      pch = strtok(buffer, DELIM);
      while (pch != NULL) {
          for(i=0; pch[i] != '\0'; i++) {
                  word_len++;
          }
          count[word_len]++;
          word_len=0;
          printf("%s\n", pch);
          pch = strtok(NULL, DELIM);
      }
      return 0;
  }
  
  int printOut(int *count) {
      int i;
      double num=0;
      double total=0;
      double average=0;
      printf("================\n");
      printf("len  count\n");
      printf("================\n");
      for(i=0;i&lt;50;i++){
          if(count[i]!=0){
              num=count[i]+num;
              total=total+(count[i]*i);
              printf("%d   %d\n",i,count[i]);
          }
      }
      average = total/num;
      printf("================\n");
      printf("average %.2f\n", average);
      printf("================\n");
      return 0;
  }
  </code></pre>