Sorting Names

Hello! I am trying to right a program that will have the user enter up to 20 names (no limit on length of name) and then sort the names. However, after I enter the first name it says that the program stopped work. Do you think you could help me locate the issue? Thanks!

Main.cpp
#include <iostream>

using namespace std;

#include "BubbleSort.h"

void main()
{
int i;
int NumNamesRead;
char * Names[20];

NumNamesRead = ReadNames(Names);
cout << "\n\tYou Entered " << NumNamesRead << " names and they were" << endl;
for (i = 0; i < NumNamesRead; i++)
cout << i + 1 << ") " << Names[i] << endl;
Sort(Names, NumNamesRead);
cout << "\n The names sorted are:" << endl;
for (i = 0; i < NumNamesRead; i++)
cout << i + 1 << ") " << Names[i] << endl;
}

BubbleSort.cpp
#include <iostream>

using namespace std;

#include "BubbleSort.h"

int ReadNames(char * Names[])
{
int i;

cout << "Enter up to 20 names" << endl;
i = -1;
do {
i++;
cout << (i + 1) << " ) ";
cin.get(*Names[i]);
if (cin.fail())
{
cin.clear();
cin.ignore(1000, '\n');
}
else;
} while (Names[i] != '\0');
return i;
}

void Sort(char * Names[], int NumNames)
{
char * Temp;
int i;
int j;

for (i = 0; i < NumNames; i++)
{
for (j = 0; j < NumNames - 1; j++)
{
if (*Names[i] < *Names[j])
{
Temp = Names[i];
Names[i] = Names[j];
Names[j] = Temp;
}
}
}
BubbleSort.h
#ifndef BUBBLE_SORT_H
#define BUBBLE_SORT_H

int ReadNames(char * []);
void Sort(char * [], int);

#endif
Topic archived. No new replies allowed.