Thanks that worked like a champ. The problem im having right now is when i try to call the functions. Not sure if im doing it right. I can find all kinds of things about calling string functions but not character array and im pretty sure my sort function is wrong. its supposed to sort the names in alphabetical order but i think its comparing every letter of the names instead of the first letter or whole name. If i called the functions with just (names, number) id get a compiler error "argument type of "char(*)[15]" is incompatible with a parameter of type"char"
Code:
#include<iostream>
using namespace std;
void getnames(char names[], int number);
void sortArray(char names[], int number);
int main()
{
int number,i=0,j,k=0,l;
char names[20][15];
do
{
cout << "How many names would you like to enter(Must be less than 20): "<<endl;
cin >> number;
if(number < 0 || number > 20)
{
cout << "You have entered a number that is out of range"<<endl;
}
}while(number < 0 || number > 20);
getnames(names[i], number);
cout << endl;
cout << "The names you entered were: " <<endl;
for(k=0;k < number; k++)
{
cout << "\n "<<names[k];
}
cout <<endl;
sortArray(names[i],number);
cout << "The names in sorted order are: " << endl;
for(i=0; i < number; i++)
{
cout << names[i] <<endl;
}
system("pause");
}
void getnames(char names[], int number)
{
int i=0;
cout << "Please enter the names you would like to enter: " << endl;
for(i=0; i < number; i++)
{
cin >> names[i];
}
return;
}
void sortArray(char names[], int number)
{
int temp;
for(int i=0; i <= number; i++)
{
for(int j=0; j < number; j++)
{
if(names[j] >names[j+1])
{
temp=names[j];
names[j]=names[j+1];
names[j+1]=temp;
}
}
}
return;
}