title: How to strtok() in for-loop?
body: <p>For given representation,</p>
  
  <pre><code>typedef struct {
    int age;
    char *firstName;
    char *lastName;
  }Record;
  </code></pre>
  
  <hr>
  
  <p>and given <code>file.txt</code>,</p>
  
  <pre><code>Age,LastName,FirstName
  50,B,A
  30,A,B
  20,X,D
  10,F,A
  90,V,E
  60,N,M
  </code></pre>
  
  <hr>
  
  <p>Below is the code in <code>main()</code>, </p>
  
  <pre><code> pFile=fopen("file.txt", "r");
   ...
   //Complete file is copied to 'readBuffer', approach inspired from  
   // http://stackoverflow.com/a/11487960/3317808
   ....
  
   char *record = strtok(readBuffer,"\n"); //Ignore header record
    record = strtok(NULL, "\n");// Read first data record(50,'B','A')
  
    for(;record != NULL; record = strtok(NULL,"\n")){
  
      printf("###Print complete record\n");
      puts(record);
  
      Record *r = malloc(sizeof(Record)*1);
  
      r-&gt;age = atoi(strtok(record,","));
  
      char *firstName = strtok(NULL,",");
      char *lastName = strtok(NULL, ",");
  
      r-&gt;firstName = strdup(firstName);
      r-&gt;lastName = strdup(lastName);
      printf("Age: %d\n", r-&gt;age);
      printf("First name: %s\n", r-&gt;firstName);
      printf("Last name: %s\n", r-&gt;lastName);
  
    }
  </code></pre>
  
  <hr>
  
  <p><code>strtok(readBuffer,",")</code>confuses compiler with <code>strtok(record,",")</code> in for-loop</p>
  
  <hr>
  
  <p>Actual output shows that tokenisation happened for only one record.</p>
  
  <pre><code>$ ./program.exe
  Print complete file
  Age,LastName,FirstName
  50,B,A
  30,A,B
  20,X,D
  10,F,A
  90,V,E
  60,N,M
  
  
  
  ###Print complete record
  50,B,A
  Age: 50
  First name: B
  Last name: A
  </code></pre>
  
  <hr>
  
  <p>How to resolve it?</p>