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