title: Split a String using strtok groups false tokens
body: <p>I am trying to read a textfile line by line and to split each line into a token. But when I try to parse</p>
  
  <pre><code>D: 0 S: 0
  push 0
  prti
  halt
  </code></pre>
  
  <p>I get an error in the first line.  The result is</p>
  
  <pre><code>0: [D:] [0 S] [0] (3 Token)
  1: [push] [0] (2 Token)
  2: [prti] (1 Token)
  3: [halt] (1 Token)
  </code></pre>
  
  <p>but I was expecting </p>
  
  <pre><code>0: [D:] [0] [S:] [0] (4 Token) &lt;--
  1: [push] [0] (2 Token)
  2: [prti] (1 Token)
  3: [halt] (1 Token)
  </code></pre>
  
  <p>the second token should be 0 and the third should be S: but as you can see in the first result the second token is "0 s", the 3rd is 0 and there is no 4th token.</p>
  
  <p>I added an example</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  char *trimwhitespace(char *str) {
    char *end;
    while(isspace((unsigned char)*str)) str++;
    if(*str == 0) return str; 
    end = str + strlen(str) - 1;
    while(end &gt; str &amp;&amp; isspace((unsigned char)*end)) end--;
    end[1] = '\0';
    return str;
  }
  
  int main(void) {
  
      FILE * fp;
      char * line = NULL;
      size_t len = 0;
      ssize_t read;
  
      int tokencounter = 0;
      char *token;
      int linecounter;
      int address = 0;
  
      char *tokentemp;
  
      fp = fopen("test.asm", "r");
      if (fp == NULL) exit(1);
  
      while ((read = getline(&amp;line, &amp;len, fp)) != -1) {   
  
          token = strtok(line, " ");
          tokencounter = 0;
  
          printf("%d: ", linecounter);
  
          while( token != NULL ) {
  
              token = trim( token );
              printf( "[%s] ", token );
              tokencounter++;                
              token = strtok(NULL, line);           
  
          }
  
          printf("(%d Token)\n", tokencounter);
  
          linecounter++;
  
      }
  
      fclose(fp);
      if (line) free(line);
      exit(1);
  
  }
  </code></pre>