Question: I know I shouldn't use C-style arrays but I was trying to look for a way to do this anyway. I'm trying to alphabetize the `const char*` array but `std::sort` didn't do it right. What am I doing wrong?

```
#include <iostream>
#include <algorithm>

int main() {

   const char * str[5] = {"alpha", "gamma", "beta", "delta", "chi"};

   int size = sizeof(str)/sizeof(*str);

   std::sort(str, str + size);

   for (int i = 0; i < size; i++) std::cout << str[i] << ", ";

}

```

It doesn't change the array at all. What am I not doing right?

Answer: 
The default `std::sort` comparison function is simply comparing *pointers* (memory addresses) with the `<` operator. It's not actually lexicographically comparing the C-strings. You need to create a custom comparison function which compares the strings lexicographically by e.g. calling `std::strcmp`

```
bool compare(const char* s1, const char* s2)
{
    return std::strcmp(s1, s2) < 0;
}

int main() 
{
   const char * str[5] = {"alpha", "gamma", "beta", "delta", "chi"};
   int size = sizeof(str)/sizeof(*str);
   std::sort(str, str + size, compare);
   for (int i = 0; i < size; i++) std::cout << str[i] << ", ";
}

```
The problem is simple: You're using the default comparison, which will just compare the pointer values. Usually these will have ascending addresses, so you won't see any change.

You'll have to write your own comparison function:

```
int comp(const char *c1, const char *c2) {
    return strcmp(c1, c2) < 0;
}

std::sort(str, str + size, &comp);

```