1 | #include <stdio.h>
|
2 | #include <stdlib.h>
|
3 | #include <string.h>
|
4 | #include "vector_utils.h"
|
5 | #include "tested_declarations.h" |
6 | #include "rdebug.h" |
7 |
|
8 | int read_vector_float(float *vec, int size, float stop_value)
|
9 | {
|
10 | if(vec == NULL((void*)0) || size <= 0 ) return -1;
|
11 | int sizeD = 0;
|
12 |
|
13 | for(int i=0; i<size; i++)
|
14 | {
|
15 | if(scanf("%f", &(*(vec+i))) != 1)
|
16 | {
|
17 | return -1;
|
18 | }
|
19 |
|
20 | if(*(vec+0) == 0)
|
21 | {
|
22 | return 0;
|
23 | }
|
24 | sizeD++;
|
25 |
|
26 | if(*(vec+i) == stop_value)
|
27 | {
|
28 | sizeD--;
|
29 | break;
|
30 | }
|
31 | }
|
32 | return sizeD;
|
33 | }
|
34 |
|
35 | int create_histogram(const float *vec, int size, int *out, int out_size)
|
36 | {
|
37 | if(vec == NULL((void*)0) || size <= 0 || out == NULL((void*)0) || out_size <= 0) return 1;
|
38 | out_size = size;
|
| Value stored to 'out_size' is never read |
39 |
|
40 | memset(out, 0, 100 * sizeof(float));
|
41 |
|
42 | for(int j = 0; j < size; j++)
|
43 | {
|
44 | float c = 0, b = 1;
|
45 |
|
46 | for(int i = 0; i < 11; i++)
|
47 | {
|
48 | if( *(vec + j) >= ++c && *(vec + j) < ++b )
|
49 | {
|
50 | *(out + (int)c) += 1;
|
51 | }
|
52 | }
|
53 |
|
54 | }
|
55 | return 0;
|
56 | }
|
57 |
|
58 | void display_vector(const int* tab, int size)
|
59 | {
|
60 | int i;
|
61 | for(i=0; i<size; i++)
|
62 | {
|
63 | printf("%d ", *(tab+i));
|
64 | }
|
65 | }
|
66 | |