title: Parsing csv file with missing entries
body: <p>I am trying to parse a csv file with C where the separator is <code>|</code> using <code>strtok</code>. The problem is that some fields are empty and thus two separators are placed next to each other. It seems that <code>strtok</code> is just skipping all empty fields and just outputting the next non-empty field. </p>
  
  <p>The thing is that I need to know at which position the token that is being read belongs to.</p>
  
  <p>Here is a very small example to illustrate.</p>
  
  <p>FILE</p>
  
  <pre><code>node|171933|||traffic_signals|||||40.4200658|-3.7016652
  </code></pre>
  
  <p>This line for instance has 10 fields, but only field 1,2,9 and 10 have some value in it.</p>
  
  <p>CODE</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt; 
  #include &lt;string.h&gt;
  
  void main()
  {
      FILE *fp;
      char lineBuf[128];
      char *token;
      int i=0;
  
      if((fp = fopen("test.txt", "r"))==NULL){
        fprintf (stderr, "\nError when opening file\n");
        return ;
      }
  
      fgets (lineBuf, sizeof(lineBuf), fp);
  
      token=strtok(lineBuf, "|\n");
      while(token!=NULL){
        printf("Element %d: %s\n",i,token); i++;
        token=strtok(NULL, "|\n");
      }
  }
  </code></pre>
  
  <p>OUTPUT</p>
  
  <pre><code>Element 0: node
  Element 1: 171933
  Element 2: traffic_signals
  Element 3: 40.4200658
  Element 4: -3.7016652
  </code></pre>
  
  <p>EXPECTED OUTPUT</p>
  
  <pre><code>Element 0: node
  Element 1: 171933
  Element 4: traffic_signals
  Element 9: 40.4200658
  Element 10: -3.7016652
  </code></pre>
  
  <p>Is there any other way to parse a line like this as expected? The number of elements in a line is not defined previously.</p>
  
  <p>I already know that the behaviour shown by <code>strtok</code> is the usual behaviour I am just asking for another way of doing it to obtain the desired results, not for the explanation of why this happens.</p>