author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Sat, 13 Dec 2008 17:58:09 +0100 | |
changeset 17 | b3731a25b9ec |
parent 9 | c3fecc82ade6 |
child 20 | 5fec678f931b |
permissions | -rw-r--r-- |
0 | 1 |
/** |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
8
diff
changeset
|
2 |
* test/demos/tree.c |
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
8
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
0 | 4 |
*/ |
5 |
||
6 |
#include <stdio.h> |
|
7 |
#include <stdlib.h> |
|
8 |
#include <fcntl.h> |
|
9 |
#include <unistd.h> |
|
10 |
||
11 |
int compare (unsigned char *a, unsigned char *b) |
|
12 |
{ |
|
13 |
if (*a > *b) |
|
14 |
return 1; |
|
15 |
return -1; |
|
16 |
} |
|
17 |
||
18 |
int main (int argc, char **argv) |
|
19 |
{ |
|
20 |
int i; |
|
21 |
int elements; |
|
22 |
int fd; |
|
23 |
unsigned char numbers[256] = { 0 }; |
|
24 |
||
25 |
fd = open ("/dev/urandom", O_RDONLY); |
|
26 |
if (fd == -1) |
|
27 |
return EXIT_FAILURE; |
|
28 |
||
29 |
elements = read (fd, numbers, 255); |
|
30 |
numbers[elements] = 0; |
|
31 |
||
32 |
qsort (numbers, elements, sizeof (unsigned char), (void *)&compare); |
|
33 |
||
34 |
for (i = 0; i < elements; i++) { |
|
35 |
printf ("Number: %d\n", numbers[i]); |
|
36 |
} |
|
37 |
||
38 |
close (fd); |
|
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
39 |
|
0 | 40 |
return EXIT_SUCCESS; |
41 |
} |