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 a = 0, c = 0, b = 1;
|
45 | a = *(vec + j);
|
46 | for(int i = 0; i < 11; i++)
|
47 | {
|
48 | if( a >= c && a < b )
|
49 | {
|
50 | *(out + (int)c) += 1;
|
51 | }
|
52 | c++;
|
53 | b++;
|
54 | }
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | }
|
102 | return 0;
|
103 | }
|
104 |
|
105 | void display_vector(const int* tab, int size)
|
106 | {
|
107 | int i;
|
108 | for(i=0; i<size; i++)
|
109 | {
|
110 | printf("%d ", *(tab+i));
|
111 | }
|
112 | }
|
113 | |