-
Notifications
You must be signed in to change notification settings - Fork 4
/
gerador.c
60 lines (45 loc) · 956 Bytes
/
gerador.c
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "utils.h"
void print_help() {
puts("-s ordenado");
puts("-h ajuda");
}
int cmp(const void *a,const void *b) {
int* x = (int*) a;
int* y = (int*) b;
return *x - *y;
}
int main(int argc, char const *argv[]) {
Bool sorted = FALSE;
int i, size;
int* array;
if(argc < 2) {
puts("Uso: gerador <tamanho> <opções>");
return 1;
}
if(argc == 3) {
if(argv[2][0] == '-') {
if(argv[2][1] == 's') sorted = TRUE;
if(argv[2][1] == 'h') {
print_help();
return 0;
}
}
else {
print_help();
return 0;
}
}
size = atoi(argv[1]) * 10000;
array = (int*) malloc(sizeof(int)*size);
srand(time(NULL));
for(i = 0; i < size; i++)
array[i] = rand();
if(sorted) qsort(array, size, sizeof(int), cmp);
printf("%i\n", size);
for(i = 0; i < size; i++)
printf("%i\n", array[i]);
return 0;
}