View Single Post
Old 01-28-2006, 05:15 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Is this a nice hint?
(observe the details)

Code:
#include <iostream>
#include <cstdlib>

using namespace std;

static const int NUM_STRINGS = 4;
int compare(const void* p1, const void* p2);

int main()
{
  char* arr_strs[] = { "test", "hi", "hello", "debug" };

  qsort(arr_strs, 4 , sizeof(char*), compare);

  for(unsigned i = 0; i < NUM_STRINGS; ++i)
  {
    std::cout<<arr_strs[i]<<" "<<std::endl;
  }

  return 0;
}

int compare(const void* p1, const void* p2)
{
  return strcmp(*(char **)p1, *(char **)p2);
}
__________________
Valmont is offline   Reply With Quote