import source from 1.3.40
[external/swig.git] / Examples / lua / arrays / example.c
1 /* File : example.c */\r
2 \r
3 #include <stdlib.h>\r
4 \r
5 /* we are using the qsort function, which needs a helper function to sort */\r
6 int compare_int(const void * a, const void * b)\r
7 {\r
8   return ( *(int*)a - *(int*)b );\r
9 }\r
10 \r
11 void sort_int(int* arr, int len)\r
12 {\r
13   qsort(arr, len, sizeof(int), compare_int);\r
14 }\r
15 \r
16 // ditto doubles\r
17 int compare_double(const void * a, const void * b)\r
18 {\r
19   return (int)( *(double*)a - *(double*)b );\r
20 }\r
21 \r
22 void sort_double(double* arr, int len)\r
23 {\r
24   qsort(arr, len, sizeof(double), compare_double);\r
25 }\r