_ _ _ _ _ _ _ _ | _| _| |_| |_ |_ | |_| |_| | | | |_ _| | _| |_| | |_| | |_|
我得到了每个数字的序列,可以打开和关闭它
样品:
int digit_sequence[10][7] = { // A,B,C,D,E,F,G /* 0 */ {1,1,0} }
其中1 = ON,0 = OFF
但是我很难让process_digit(int digit,int position)函数起作用.
我很难将序列[10] [7]翻译成数字[4] [MAX_DIGITS * 4]
一个善良的灵魂能帮帮我吗?
我一直在阅读高尔夫代码七段挑战,但即使我理解这个理论,仍然很难说服我的大脑用多个阵列做我想做的事情.
忽略ASCII艺术,问题如下:
Write a program that prompts the user for a number and then displays the number using characters to simulate the effect of a seven-segment display.
…
Characters other than digits should be ignored. Write the program so that the maximum number of digits is controlled by a macro named MAX_DIGITS which has the value 10. If the number contains more than this number of digits,the extra digits are ignored. Hints: Use two external arrays. One is the
segments
array […] which stores data representing the correspondence between digits and segments. The other array,digits
,will be an array of characters with 4 rows (since each segmented digit is 4 characters high) andMAX_DIGITS * 4
columns (digits are three characters wide but a spaces is needed between digits for readability). Write your program as four functions:main
,[…]06002
clear_digits_array
will store blank characters into all elements of the digits array.process_digit
will store the seven-segment representation ofdigit
into a specified position in thedigits
array (positions range from0
toMAX_DIGITS - 1
).print_digits_array
will display the rows of the digits array,each on a single line […].
解决方法
每个细分的行号相同.
0: _ _ 1: |_| |_| ... 2: |_| |_| 3:
但是,列因位置而异.每个位置是一个4个字符宽度的“迷你矩阵”(3个用于段,1个用于空格:’| _ |’).因此,我们修复了分段线,并在“迷你矩阵”上将其列与(位置* 4)相加.
0123 4567 89AB _ _ _ |_| |_| |_| ... |_| |_| |_| pos0 pos1 pos2
得到它了?代码将是这样的:
void process_digit(int digit,int position){ int i; for(i=0;i<7;i++){ if(segments[digit][i]==1) /* Has digit the i segment? */ switch(i){ case 0: digits[0][1+position*4]='_';break; case 1: digits[1][2+position*4]='|';break; case 2: digits[2][2+position*4]='|';break; case 3: digits[2][1+position*4]='_';break; case 4: digits[2][0+position*4]='|';break; case 5: digits[1][0+position*4]='|';break; case 6: digits[1][1+position*4]='_';break; } } }
(您可以选择’ – ‘和’_’,或者可能更改某些行)
希望能帮助到你.