title: How to read all the double numbers from a string using sscanf in c?
body: <p>I have a text file which contains lines in different formats. I want to read all the numbers in this text file using c. And I want to read the numbers as a double precision number. The content of the text file is below:</p>
  
  <pre><code> 1,'            ',  13.8000,2,     0.000,     0.000,   1,   1,1.04500,  11.3183,   1
   2,'            ',  13.8000,2,     0.000,     0.000,   1,   1,0.98000,  19.9495,   1
   17,'1 ',1,   1,   1,  6000.000,   300.000,     0.000,     0.000,     0.000,     0.000,   1
   16,'16',  4000.000,   401.887,  9999.000, -9999.000,1.00000,  0,   200.000,   0.00000, 0.00550
  </code></pre>
  
  <p>I used fopen to read the file and used sscanf to scan the content in a single line. The code I have so far is below:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  FILE *fptr;
  if ((fptr = fopen("rggs.raw","r")) == NULL){
     fprintf(mapFile,"Error! opening file");
  }
  int line=0;
  char input[512];
  int total_n = 0;
  double ii;
  int nn;
  while( fgets( input, 512,fptr)){
      line++;
          total_n = 0;
          while (1 == sscanf(input + total_n, "%lf", &amp;ii, &amp;nn)){
              total_n += nn;
              printf(": %lf\n", ii);
          }
  }
  printf("\n\nEnd of Program\n");
  fclose(fptr);
  </code></pre>
  
  <p>The output of the code is</p>
  
  <pre><code>: 1.000000
  : 2.000000
  : 17.000000
  : 1.000000
  : 0.000000
  : 0.000000
  : 0.000000
  : 16.000000
  : 0.000000
  : 9.000000
  : 0.000000
  : 0.000000
  : 550.000000
  
  
  End of Program
  </code></pre>
  
  <p>and it doesn't contain all the numbers in my text file. </p>