1 /***
2 File Name : qsort_example.c
3 Purpose :
4 Creation Date : 09-02-2010
5 Last Modified : Di 09 Feb 2010 19:57:06 CET
6 Created By :
7 ***/
8 #include <string.h>
9 #include <stdlib.h>
10 #include <stdio.h>
11
12
13 int find(char x, char *l)
14 {
15 int i;
16 for (i=0; l[i] != x; i++);
17 return i;
18 }
19
20 static int cmp(const void *a, const void *b)
21 {
22 /*char A[] = "rovhupdtjbxwaqzleimfgcksny\0";*/
23 char A[] = "abcdefghijklmnopqrstuvwxyz\0";
24 int x = find(*(char*)a, A), y = find(*(char*)b, A);
25 if (x==y) return 0;
26 else if (x<y) return -1;
27 else if (x>y) return 1;
28 }
29
30 int main(int argc, char* argv[])
31 {
32 int i;
33
34 qsort(&argv[1], argc - 1, sizeof(char*), cmp);
35 for (i=1; i < argc; ++i) printf("%s\n", argv[i]);
36 return 0;
37 }