title: C++ text menu: writing, reading, and sorting data
body: <p>So my assignment is to create multiple classes for a Person, Name, ID #, Address, and Phone #.</p>
  
  <p>Name makes up: First, Middle, and Last name.
  ID # makes up: 9 digits.
  Address makes up: street, city, state, and 5 digit zip code.
  Phone # makes up: 3 digit area code and 7 digit number.
  Person makes up: a full Name (First, Middle, Last), an Address, a Phone # (area code, and number), and a ID # (9 digit number).</p>
  
  <p>I have accomplished all of this.  My problem is we are also supposed to make a menu, to specify how many people the user wishes to type in, where they want to save the file, if they want to read or write to a file specified by the user, and being able to sort the people by name (last, first, or middle) or by ID #, and save the sorted list to a user specified file.</p>
  
  <p>I have all the code written, but my write function is not working for some reason.  What happens is I run the program, the menu I created pops up.  I select '1' enter the file, then the menu pops up again, and I select '2' to make sure it cant read since there is nothing in the specific file I am testing with. Next, I select '3' to write People to the user specified file.  It prompts me for how many People I want to enter and I enter a number (2).  Then the prompt for typing in the first name pops up and I get some error saying "an unhandled win32 exception occured" in my project .exe...</p>
  
  <p>Here is my code:</p>
  
  <pre><code>//global variables
  char filename[256];
  fstream file2 (filename);
  
  int r;
  Person * stuArrPtr=new Person[r];
  
  int w;
  Person * stuArrPtr2=new Person[w];
  
  //global functions
  void WriteUserFile () {
  //write as many ppl as specified to a file...
  // int w;
   cout &lt;&lt; "How many students would you like to enter?: ";
   cin  &gt;&gt; w;
  
  // Person * stuArrPtr2=new Person[w];
   if (!file2.is_open ()) {
    cout &lt;&lt; "File did not open" &lt;&lt; endl;
    file2.clear ();
    file2.open (filename, ios_base::out);
    file2.close ();
    file2.open (filename, ios_base::out | ios_base::in);
  
   }
   else {
    for (int i = 0; i &lt; w/*!file2.eof ()*/; i++) {
     stuArrPtr2[i].InputPerson();
     if (strcmp(stuArrPtr2[i].PersonNam.GetFirst(), "EOF") != 0)
      stuArrPtr2[i].Display (file2);
    }
   }
   cout &lt;&lt; endl;
  // delete [] stuArrPtr2;
  }
  
  void Menu () {
   int option;
   do {
    //display menu
    cout &lt;&lt; " Type '1' - to open a file for reading or writing" &lt;&lt; endl &lt;&lt; endl;
    cout &lt;&lt; " Type '2' - to read from the file you specified in '1'" &lt;&lt; endl &lt;&lt; endl;
    cout &lt;&lt; " Type '3' - to write from the file you specified in '1'" &lt;&lt; endl &lt;&lt; endl;
    cout &lt;&lt; " Type '4' - sort students by last name" &lt;&lt; endl &lt;&lt; endl;
    cout &lt;&lt; " Type '5' - sort students by first name" &lt;&lt; endl &lt;&lt; endl;
    cout &lt;&lt; " Type '6' - sort students by middle name" &lt;&lt; endl &lt;&lt; endl;
    cout &lt;&lt; " Type '7' - sort students by ID number" &lt;&lt; endl &lt;&lt; endl;
    cout &lt;&lt; " Type '8' - exit" &lt;&lt; endl &lt;&lt; endl;
  //  cout &lt;&lt; " Enter appropriate number here: [ ]\b\b";
    cout &lt;&lt; " Enter appropriate number here: ";
    cin &gt;&gt; option;
  
    switch(option) {
     case 1:
      cout &lt;&lt; "you entered option 1" &lt;&lt; endl;
      OpenUserFile ();
      break;
     case 2:
      cout &lt;&lt; "you entered option 2" &lt;&lt; endl;
      ReadUserFile ();
      break;
     case 3:
      cout &lt;&lt; "you entered option 3" &lt;&lt; endl;
      WriteUserFile ();
      break;
     case 4:
      cout &lt;&lt; "you entered option 4" &lt;&lt; endl;
      SortLastName ();
      break;
     case 5:
      cout &lt;&lt; "you entered option 5" &lt;&lt; endl;
      SortFirstName ();
      break;
     case 6:
      cout &lt;&lt; "you entered option 6" &lt;&lt; endl;
      SortMiddleName ();
      break;
     case 7:
      cout &lt;&lt; "you entered option 7" &lt;&lt; endl;
      SortIDNumber ();
      break;
     case 8:
      cout &lt;&lt; "you entered option 8" &lt;&lt; endl; //exit
      delete [] stuArrPtr;
      delete [] stuArrPtr2;
      break;
     default:
      cout &lt;&lt; "you screwed up, no big deal, just try again!" &lt;&lt; endl;
    } //end switch
    //if (option == 6) {
    // break;
    //}
   } while (option != 8);
  // system("pause"); 
  }
  
  void main () {
  Menu ();
  }
  /////////////////END OF CODE///////
  </code></pre>
  
  <p>Sorry the code is so long, and any help is very, very much appreciated!</p>