language: C (gcc-4.7.2)
date: 293 days 21 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int compare(const void* a1, const void* a2)
{
    const char** s1   = a1;
    const char** s2   = a2;
    const int result = strcmp(*s1, *s2); 
    return result;
}
 
int main()
{
    char* s[] = { "e", "d", "c", "b", "a" };
    const size_t s_element_size  = sizeof(s[0]);
    const size_t s_element_count = sizeof(s) / s_element_size;
    size_t i;
 
    for (i = 0; i < s_element_count; i++)
    {
        printf("[%s]\n", s[i]);
    }
    printf("\n");
 
    qsort(s, s_element_count, s_element_size, compare);
 
    for (i = 0; i < s_element_count; i++)
    {
        printf("[%s]\n", s[i]);
    }
 
    return 0;
}