title: fscanf format specifier - columnwise numeric data ending with or without a comment string
body: <p>I have a datafile with say 3 columns containing float numbers (assume number columns are fixed for now) but the last column is a string of characters that contains spaces (but in a single line).</p>
  
  <p>The problem am facing is not all lines of text file may contain the last comment string, otherwise using </p>
  
  <p><code>fscanf(&lt;file pointer&gt;, %f %f %f %[^\n]%*c,&amp;var1,&amp;var2,&amp;var3,temp)</code> works</p>
  
  <p>as below: (for 3 rows of data)</p>
  
  <pre><code>FILE *fp1=NULL;
  printf("HELLO\n");
  double value1 = 0.00,value2 = 0.00,value3=0.00;
  int i=0;
  char temp[200];
  
  fp1 = fopen(textfile,"r");
  rewind(fp1);
  if(fp1 == 0)    { 
      perror("ERROR OPENING FILE ");
      return ;
  }
  char format[] = "%lf %lf %lf %[^\n]s%*c";
  i=3;
  while(i--)
  {
      fscanf(fp1,format,&amp;value1,&amp;value2,&amp;value3,temp) ;
      printf("%lf,%lf,%lf - ",value1,value2,value3);
      printf("%s\n",temp);
  }
  fclose(fp1);
  </code></pre>
  
  <hr>
  
  <p>Above code works for if each row contains a comment as last column, but lines are getting combined if the comment is not there at the end of row.</p>
  
  <h2>For example, it fails for file with data below:</h2>
  
  <pre><code>1.00 1.1 1.4 //this is first line 
  2.00 2.1 2.4 
  4.00 4.1 4.4 //this is fourth line
  3.00 3.1 3.4
  5.00 5.1 5.4 //this is fifth line
  </code></pre>
  
  <h2>And gives output as:</h2>
  
  <pre><code>HELLO
  1.000000,1.100000,1.400000 - //this is first line
  2.000000,2.100000,2.400000 - 4.00 4.1 4.4 //this is fourth line
  3.000000,3.100000,3.400000 - 5.00 5.1 5.4 //this is fifth line
  </code></pre>
  
  <p>Hope my issue is clear. </p>