Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Prints a histogram using the given `values` array.
- // The supplied `values` array should have values in range [0.0, 1.0], and contain at least `nb_values` entries.
- // `nb_values` represents the number of values to be printed (and thus the lengths of both arrays).
- // `descriptions` must contain strings labelling each entry. At least `nb_values` strings are expected.
- void print_histogram(double* values, uint8_t nb_values, char** descriptions) {
- for(int8_t slice = 9; slice != -1; slice--) {
- printf("%2d%% ", slice * 10);
- for(uint8_t valueID = 0; valueID < nb_values; valueID++) {
- putchar( (values[valueID] > (double)slice / 10) ? '|' : ' ');
- // Pad to the right
- for(uint8_t i = strlen(descriptions[valueID]); i != 0; i--) {
- putchar(' ');
- }
- }
- putchar('\n');
- }
- printf(" ");
- for(uint8_t valueID = 0; valueID < nb_values; valueID++) {
- printf("%s ", descriptions[valueID]);
- }
- putchar('\n');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement