title: C++ Sorting an Array in Alphabetical order using strcpy and strcmp while taking data from a file?
body: <p>I almost have it working however, it is seperating the last names that start in caps and the ones that do not. </p>
  
  <p>Example file </p>
  
  <p>LastName FirstName DaysofRental BalanceDue</p>
  
  <p>Smith Joe 15 100.50</p>
  
  <p>Doe John 10 95.20</p>
  
  <p>Anderson Paul 30 20.00</p>
  
  <p>O'Donell Miriam 10 24.30</p>
  
  <p>Foster Sam 30 15.00</p>
  
  <p>Zom Pete 10 20.00</p>
  
  <p>Mock Chilly 100 30</p>
  
  <p>smitty Chris 200 200</p>
  
  <p>xu Conor 1 200</p>
  
  <p>anilo steve 0 0</p>
  
  <p>What "Sorted" file is outputing </p>
  
  <p>LastName            FirstName           DaysofRental        BalanceDue          </p>
  
  <p>Anderson            Paul                30                  $20.00               </p>
  
  <p>Doe                 John                10                  $95.20               </p>
  
  <p>Foster              Sam                 30                  $15.00               </p>
  
  <p>Mock                Chilly              100                 $30.00               </p>
  
  <p>O'Donell            Miriam              10                  $24.30               </p>
  
  <p>Smith               Joe                 15                  $100.50              </p>
  
  <p>Zom                 Pete                10                  $20.00               </p>
  
  <p><strong>anilo               steve               0                   $0.00<br>
  smitty              Chris               200                 $200.00<br>
  xu                  Conor               1                   $200.00</strong>         </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;fstream&gt;
  #include &lt;string.h&gt;  
  using namespace std;
  const int STRINGSIZE = 30;
  const int LISTSIZE  = 10;
  const int HEADSIZE = 4;
  
  typedef char STRING30[STRINGSIZE];
  typedef STRING30 NAMES[LISTSIZE];
  
  int main(int argc, char** argv)
  {
  ofstream outfile;
  outfile.open("sorted.txt");
  
  int count, 
      count2,
      mindex;
  
  int rdays[LISTSIZE],
      hrdays;
  
  double baldue[LISTSIZE],
         totalbaldue, 
         hbaldue, 
         tempnum;
  
  NAMES first, 
        last, 
        header;
  
  STRING30 mname, 
           tempname;  
  
  ifstream in;
  in.open("invoice1_test1.txt");
  
  //Input Section
  
  if(in.is_open())
  {
      in &gt;&gt; header[0]
         &gt;&gt; header[1] 
         &gt;&gt; header[2] 
         &gt;&gt; header[3]; 
  
      int count = 0;
  
      while(!in.eof())
      {
          in &gt;&gt; last [count] 
             &gt;&gt; first[count]
             &gt;&gt; rdays[count]
             &gt;&gt; baldue[count];
          count++;
      }
      in.close();     
  }
  
  else 
  
  {
      cout &lt;&lt; "File failed to open" &lt;&lt; endl;
  }
  
      for(count = 0; count &lt; LISTSIZE; count++)
  {
      mindex = count;
      strcpy(mname, last[count]);
      for(count2 = count; count2 &lt; LISTSIZE; count2++)
      {
          if(strcmp(last[count2], mname) == -1)
          {
              mindex = count2;
              strcpy(mname, last[count2]);
          }
      }
  
      strcpy(tempname, last[count]);
      strcpy(last[count], mname);
      strcpy(last[mindex], tempname);
  
      strcpy(tempname, first[count]);
      strcpy(first[count], first[mindex]);
      strcpy(first[mindex], tempname);
  
      tempnum = rdays[count];
      rdays[count]= rdays[mindex];
      rdays[mindex]= tempnum;
  
      tempnum = baldue[count];
      baldue[count] = baldue[mindex];
      baldue[mindex] = tempnum;
  }
  outfile &lt;&lt; setiosflags(ios::showpoint | ios::fixed) &lt;&lt; setprecision(2);
  
  outfile &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; header[0] &lt;&lt; setw(20) &lt;&lt; header[1] &lt;&lt; setw(20) &lt;&lt; header[2] &lt;&lt; setw(20) &lt;&lt; header[3] &lt;&lt; endl;
  
  for(int count = 0; count&lt;LISTSIZE; count++)
  {
      outfile &lt;&lt; left &lt;&lt; setw(20) &lt;&lt; last[count] &lt;&lt; setw(20) &lt;&lt; first[count] &lt;&lt; setw(20) &lt;&lt; rdays[count] &lt;&lt; "$" &lt;&lt; setw(20) &lt;&lt; baldue[count] &lt;&lt; endl;
  }
  </code></pre>