Hi I'm New Here. Although I have been reading in the past and appreciate all the help that the board has given me already. I have a homework assignment that I need the user to enter how many names they want to enter, then enter that number of names, display them, then sort them and display them. However, my sort function is blowing up and I can't figure out for the life of me why. I have been looking at this thing for so long and am so confused as to why it is not working. Any help is appreciated.
#include <iostream>
using namespace std;
#include <string.h>
#include "ReadString.h"
#include "MySort.h"
void main ()
{
long i;
long NumNames;
char ** pNames;
cout << "How many names do you want? ";
cin >> NumNames;
cin.get ();
cout << "Enter " << NumNames << " strings: " << endl;
pNames = new char * [NumNames];
for (i = 0; i < NumNames; i++)
pNames [i] = ReadString ();
cout << "You entered:\n" << endl;
for (i = 0; i < NumNames; i++)
cout << pNames [i] << endl;
for (i = 0; i < NumNames; i++)
delete [] pNames [i];
delete [] pNames;
SortNames(pNames, NumNames);
cout << "After sorting the names" << pNames [NumNames] << endl;
}
And here is my Sort file (it's a bubble sort)
#include "MySort.h"
#include <locale>
void SortNames (char ** pNames, long NumNames)
{
char * temp ;
char Letter1, Letter2 ;
bool Sorted ;
do {
Sorted = true ;
NumNames-- ;
for (int i = 0; i < NumNames; i++ )
{
for ( int j = 0; j < 20; j++ )
{
Letter1 = toupper(pNames[i][j]) ;
Letter2 = toupper(pNames[i+1][j]) ;
if (Letter1 > Letter2)
{
temp = pNames[i] ;
pNames[i] = pNames[i+1] ;
pNames[i+1] = temp ;
Sorted = false ;
break ;
}
else
if (Letter1 == Letter2)
Sorted = false ;
else
break ; // in order for now
}
}
} while (!Sorted) ;
}