title: How to read an array from a file, sort it, and print it into another file?
body: <p>I have on my local machine a file named "data.in" with this content:</p>
  
  <pre><code>1
  5
  6
  6
  8
  10
  33
  24
  20
  3
  </code></pre>
  
  <p>And the source code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main (void)
  {
      int n,i,a,V[i],ch,aux;
      FILE *f1, *f2;
  
      f1 = fopen("data.in", "r");
      f2 = fopen("data.out", "w"); //create data.out
  
      char line[1024];
      n = 0;
      while( fgets(line,sizeof(line),f1) != NULL)
         n++; // n = number of lines from the file
  
      for (i=0; i&lt;n; i++)
          fscanf(f1,"%d", &amp;V[i]); //reading the array from data.in
  
      do {
          ch=0;
          for (i=0; i&lt;n-1; i++)
              if (V[i]&gt;V[i+1])
              {
                  aux=V[i]; V[i]=V[i+1]; V[i+1]=aux; ch=1;
              }
      } while (ch); //Bubble sort
  
      for (i=0; i&lt;n; i++)
          fprintf(f2, "%d\n", V[i]); // print the array into data.out
  
      fclose(f1);
      fclose(f2);
  
  }
  </code></pre>
  
  <p>The compilation goes fine but whenever I execute it, data.out contains only:</p>
  
  <pre><code>0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  </code></pre>
  
  <p>I even tried to print only the array but it is still a bunch of zeros.
  I even tried to modify data.in to have all the numbers on the same line but the output was still only a bunch of zeros. I must be missing something...</p>
  
  <p>I'm kind of stuck here so  Any help would be appreciated.</p>