Need more info. What if you had first & last names to sort
This piece of code is pretty good. I have been looking for something quite different. Which codes would you use to sort first and last names instead of just the first name?
I tried and failed. see my codes.
-----Configuration: alphabetizeName - Win32 Debug-----------
Compiling...
alphabetizeName.cpp
c:\documents\desktop\badtest\alphabetizename.cpp(5 6) : error C2059: syntax error : ')'
Error executing cl.exe.
alphabetizeName.obj - 1 error(s), 0 warning(s)
The codes:
/*
first tested 2/2/02
Purpose: Sort in alphabetical order a list of strings of string array.
*/
#include <iostream>
#include <cstring>
using namespace std;
#define const elems 12
void showArray(char strings[][17], int);
int main()
{
char (strings[12][17]) = {
"Carl Billion", "Smith Birt", "Al Jim",
"Albert Jim", "Stan Karty", "Rose Amre",
"Bay Terr", "Johnson Erab", "Allison Carr",
"Jean Joey", "Will Bill", "James Gart"
};
cout << "The unsorted names are: \n\n";
showArray(strings, 12);
qsort( strings, 12, 17, (int (*) ( const void*, const void*) )strcmp);
for( int i = 0; i < 12; i++ )
// puts( strings[i] );
cout << (strings[i]) << endl;
return 0;
}
// function definitions ==========================
void showArray(char strings[12][17], int elems)
{
for (int i = 0; i < elems; i++)
{
for ( int j = 0 ; j < elems; j++)
cout << strings[i][j]<<" ";
cout << endl;
}
cout<<endl<<endl;
}