I want to create a bar-graph display using a string. The string needs to be 14 characters long, filled from the left with either a '#' character or a ' ' depending on the value of a variable, level.
Each character represents 1/14 of the total (this is my display width), so as level rises from 0 to 14, there will be more # characters on the left, and fewer spaces, viz:
I started by using a for loop, but it looked very messy. Is there a shortcut in ANSI C?
Note: I'm a newbie, so would appreciate simple suggestions, without pointers if possible!
Each character represents 1/14 of the total (this is my display width), so as level rises from 0 to 14, there will be more # characters on the left, and fewer spaces, viz:
Code:
If level < 1, the string should be: " " If level == 1, the string should be: "# " If level == 7, the string should be: "####### " If level == 14, the string should be: "##############"
Note: I'm a newbie, so would appreciate simple suggestions, without pointers if possible!
Comment