The sort looks OK to me. What's wrong with the output? And have you verified that everything reads into the structures properly from the file?
Note : I assume you have precisely 30 elements? If not, all bets are off because your sort code assumes that. I notice a "peek" and an EOF test in the read-from-file stage, so perhaps you do NOT know you have exactly 30 elements. Since the array is completely uninitialized, you could be sorting garbage at the end of the list which makes it up to the front?
VernonDozier
Posting Expert
5,675 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 738
Skill Endorsements: 18
When in doubt, initialize with something printable, easily identifiable which no real record would contain, and which will almost certainly be at the end alphabetically...
const string INVALID_RECORD = "zzzzz";
// now before reading into the file, fill it all in with z's. The real records will overwrite this.
for(int i = 0; i < SIZE; i++)
{
info[i].last = INVALID_RECORD;
info[i].first = INVALID_RECORD;
info[i].telephone = INVALID_RECORD;
}
Stick this at the very top of main and see what happens.
VernonDozier
Posting Expert
5,675 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 738
Skill Endorsements: 18
Question Answered as of 1 Year Ago by
VernonDozier