In KN Kings "C-Programming: A Modern Approach", chapter 10, exercise 7, the task is to convert a digital digit from normal digits to 7-segment digits in ASCII art, for example:
_ _ _ _ _ _ _ _ | _| _| |_| |_ |_ | |_| |_| | | | |_ _| | _| |_| | |_| | |_|
I got a sequence for each digit, where to turn it on and off
Example:
int digit_sequence[10][7] = { // A,B,C,D,E,F,G /* 0 */ {1,1,1,1,1,1,0} }
Where 1 = ON, 0 = OFF
but it's hard for me to work with the function process_digit(int digit, int position)
.
It’s hard for me to translate from sequence[10][7]
to digits[4][MAX_DIGITS*4]
Can a gracious soul help me?
I read the seven-segment golf challenge, but although I understand this theory, it's still hard for me to convince my brain to do what I want with multiple arrays.
Ignoring the art of ASCII, the question reads:
Write a program that asks the user for a number and then displays the number using characters to simulate the effect of a seven-segment display.
...
Characters other than numbers should be ignored. Write the program so that the maximum number of digits is controlled by a macro called MAX_DIGITS, which has a value of 10. If the number contains more than this number of digits, additional digits are ignored. Tips. Use two external arrays. One of them is the segments
[...] array, which stores data representing the correspondence between numbers and segments. Another digits
array will be an array of characters with 4 lines (since each segmented digit has 4 characters) and MAX_DIGITS * 4
columns (the numbers are three characters wide, but a space is required between the numbers to read). Write your program in four functions: main
, [...]
void clear_digits_array(void); void process_figit(int digit, int position); void print_digits_array(void);
clear_digits_array
will store empty characters in all elements of the digit array. process_digit
save the seven-segment representation of digit
at the specified position in the digits
array (positions range from 0
to MAX_DIGITS - 1
). print_digits_array
display the lines of an array of numbers, each of which will contain one line [...].