title: C++: Reading and Sorting Binary Files
body: <p>I've been scratching my head and putting this homework off for a couple days but now that I hunker down to try and do it I'm coming up empty. There's 4 things I need to do.</p>
  
  <p>1) Read a binary file and place that data into arrays</p>
  
  <p>2) Sort the list according to the test scores from lowest to highest</p>
  
  <p>3) Average the scores and output it</p>
  
  <p>4) Create a new binary file with the sorted data</p>
  
  <p>This is what the binary data file looks unsorted</p>
  
  <p>A. Smith    89</p>
  
  <p>T. Phillip 95</p>
  
  <p>S. Long 76</p>
  
  <p>I can probably sort since I think I know how to use parallel arrays and index sorting to figure it out, but the reading of the binary file and placing that data into an array is confusing as hell to me as my book doesn't really explain very well.</p>
  
  <p>So far this is my preliminary code which doesn't really do much:</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;Windows.h&gt;
  using namespace std;
  
  
  
  int get_int(int default_value);
  int average(int x, int y, int z);
  
  int main() 
  
     {
  
  
      char filename[MAX_PATH + 1];
      int n = 0;
      char name[3];
      int grade[3];
      int recsize = sizeof(name) + sizeof(int);
      cout &lt;&lt; "Enter directory and file name of the binary file you want to open: ";
      cin.getline(filename, MAX_PATH);    
  
      // Open file for binary write.
      fstream fbin(filename, ios::binary | ios::in);
      if (!fbin) {
      cout &lt;&lt; "Could not open " &lt;&lt; filename &lt;&lt; endl;
      system("PAUSE");
      return -1;
     }
  
  }
  </code></pre>
  
  <p>Sorry for such a novice question.</p>
  
  <p>edit: Sorry what the data file stated earlier is what it SHOULD look like, the binary file is a .dat that has this in it when opened with notepad:</p>
  
  <p>A.Smith ÌÌÌÌÌÌÌÌÌÌÌY    T. Phillip ÌÌÌÌÌÌÌÌ_    S. Long ip ÌÌÌÌÌÌÌÌL    J. White p ÌÌÌÌÌÌÌÌd   </p>