Did you post your exact program? Because the code you posted doesn't fit the results you posted.
>>inFile >> fName >> lName[i++] >> age >> sex >> wTime;
lName array is ok, but on every iteration of that loop the program just simply overwrites whatever was read on the previous loop for the other variables. I'd suggest you use a structure to contain all the information, then sort the structures.
struct person
{
string lName;
string fName;
int age;
// etc etc
};
struct person array[MaxPeople];
//put the next two lines inside the read-data loop.
nFile >> array[i].fName >> array[i].lName>> array[i].age >> array[i].sex >> array[i].wTime;
++i;
Now all you have to do is use selection sort to sort the structures by last name. use memcpy() to exchange the entire structure, not just the individual elements of the structure will make it work faster.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Offline 21,957 posts
since Aug 2005