title: How to read a file with multiple lines of both floats and integers in C?
body: <p>Yeah, so I'm having difficulty trying to read a file with multiple lines of just numbers (a mix of floats and integers on each line).  I have a .txt file, and from there I'm trying to scan those lines, and identify if the second float is bigger than the first float, and make a decision based on the result.  So far, it works, but the problem is that I am not able to get to the second or third line, as the program just stops after the first line.</p>
  
  <p>Here's a sample of the .txt file:</p>
  
  <pre><code> 9.64 6.30 3
   2.77 3.98 10
   5.63 4.20 5
   0.00 0.00 0
  </code></pre>
  
  <p>*When the scanf hits 0 for all values, it breaks out of the loops and stops the program.  Also, I don't necessarily know how many lines there are in the file, but I do know that for every line there will be two floats and 1 integer (in that order).</p>
  
  <p>Now with these numbers, I'm trying to compare the float values to determine something, and then use the integer and the floats to compute an answer which will then be printed onto a separate .txt file.</p>
  
  <p>Here's a sample code I made that follows the same structure as the one I'm working on (by the way, I have looked at getf() function and arrays but I'm pretty much a bigginer, so I'm still confused about how/where to use them).</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;math.h&gt;
  
  int main (void)
  {
      int amount, x;
      float first, second, current_value, total_positive, total_negative;
      FILE *fin = fopen("numbersin.txt", "r");
      FILE *fout = fopen("resultout.txt", "w");
  
      x=1;
      amount=0;
      total_positive=0;
      total_negatve=0;
  
      while(x=1)
      {
          fscanf(fin, "%f %f %d", &amp;first, &amp;second, &amp;amount);
          if((second-first) &gt; 0)
          {
              current_value=amount*(first+second);
              total_positive=total_positive+current_value;
              fprintf(fout, "%0.2f %0.2f %d:increase = %0.2f, total increase = %0.2f", first, second, amount, current_value, total_positive);
          }
          else if((second-first) &lt; 0)
          {
              current_value=amount*(first+second);
              total_negative=total_negative+current_value;
              fprintf(fout, "%0.2f %0.2f %d:decrease = %0.2f, total decrease = %0.2f", first, second, amount, current_value, total_negative);
          }
          else((first==0)&amp;&amp;(second==0)&amp;&amp;(amount==0));
          {
              break;
          }
      }
  
      fclose(fin);
      fclose(fout);
      system("notepad resultout.txt");
      system("pause");
      return 0;
  }
  </code></pre>