Try -
Code:
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
void showArray(char strings[][17], int);
typedef int (*cmpfunc)(const void*,const void*);
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, (cmpfunc)strcmp);
for( int i = 0; i < 12; i++ )
cout << (strings[i]) << endl;
char* found = (char*)bsearch("Will Bill",strings,12,17,(cmpfunc)strcmp);
cout << "FOUND: " << found << '\n';
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;
}