title: Sorting data from text file
body: <p>I need to write a program that reads an unknown number of numerical data from a text file into an array and then uses a sorting parameter to sort the numbers. I've been trying for hours and I can't get the program to work</p>
  
  <pre><code>void sort(double &amp;, double arr[], int s);
  
  int main()
  {
      fstream myfile;
      int size, i = 0;
      const int n = 1000;
      double x[n];
  
      //reading data
      myfile.open("data.txt");
      if (myfile.fail())
      {
          cout &lt;&lt; "Error Opening File" &lt;&lt; endl;
          exit(1);
      }
      while (!myfile.eof())
      {
          myfile &gt;&gt; x[i];
          cout &lt;&lt; x[i] &lt;&lt; endl;
          i++;
      }
      size = i - 1;
      cout &lt;&lt; size &lt;&lt; " number of values in file" &lt;&lt; endl;
      myfile.close();
  
      i = 0;
      while (size &gt; i)
      {
          cout &lt;&lt; x[i] &lt;&lt; endl;
          i++;
      }
      //sorting
      sort(x[n], x[n], size);
      i = 0;
      while (size &gt; i)
      {
          cout &lt;&lt; x[i] &lt;&lt; endl;
          i++;
      }
      return 0;
  }
  
  void sort(double &amp;, double arr[], int s)
  {
      bool swapped = true;
      int j = 0;
      int tmp;
      while (swapped) 
      {
          swapped = false;
          j++;
          for (int i = 0; i &lt; s - j; i++) 
          {
              if (arr[i] &gt; arr[i + 1])
              {
                  tmp = arr[i];
                  arr[i] = arr[i + 1];
                  &amp;[i + 1] = &amp;tmp;
                  swapped = true;
              }
          }
      }
  }
  </code></pre>