title: C - split a string with pipes using strtok
body: <p>I have a string "1|4|1577|1|10.22.33|7001390280000019|||||172.20.5.20|1" and I want to split this string to get a result like this:</p>
  
  <pre><code>1
  4
  1577
  10.22.33
  7001390280000019
  null
  null
  null
  null
  172.20.5.20
  1
  </code></pre>
  
  <p>But when I use strtok in a while cycle, the pipes that doesn't have any content are not showing, so my result looks like this:</p>
  
  <pre><code>1
  4
  1577
  1
  10.22.33
  7001390280000019
  172.20.5.20
  1
  </code></pre>
  
  <p>How can I get this result?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>int main(argc,argv)
  int argc;
  char *argv[];
  {
      char *var1="1|4|1577|1|10.22.33|7001390280000019|||||172.20.5.20|1";
      char *var2=malloc(strlen(var1)+1);
      strcpy(var2,var1);
      while ((var2 = strtok(var2, "|")) != NULL){
          printf("&lt;&lt;%s&gt;&gt;\n", var2);
          var2= NULL;
      }
      return 0;
  }
  </code></pre>
  
  <p>Thanks in advance</p>