## c实现动态时间打印. 请教。

calvary 发布于 2013/11/21 16:49

如题， 是前几年一公司面试的题.  获取系统时间， 动态打印时间.按照LED显示格式  .

0

```#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>

uint8_t hehe[10][5] = { { 7, 5, 5, 5, 7 }, // 0
{ 1, 1, 1, 1, 1 }, // 1
{ 7, 1, 7, 4, 7 }, // 2
{ 7, 1, 7, 1, 7 }, // 3
{ 5, 5, 7, 1, 1 }, // 4
{ 7, 4, 7, 1, 7 }, // 5
{ 7, 4, 7, 5, 7 }, // 6
{ 7, 1, 1, 1, 1 }, // 7
{ 7, 5, 7, 5, 7 }, // 8
{ 7, 5, 7, 1, 7 }, // 9
};

int main() {
struct tm * st;
system("clear");
int i;
int t1, t2, t3, t4, t5, t6;
while (1) {
time_t timep;
time(&timep);
st = localtime(&timep);
t1 = st->tm_hour / 10;
t2 = st->tm_hour % 10;
t3 = st->tm_min / 10;
t4 = st->tm_min % 10;
t5 = st->tm_sec / 10;
t6 = st->tm_sec % 10;
for (i = 0; i < 5; i++) {
printf(((hehe[t1][i] & mask1) == 0) ? " " : "█");
printf(((hehe[t1][i] & mask2) == 0) ? " " : "█");
printf(((hehe[t1][i] & mask3) == 0) ? " " : "█");
printf(" ");
printf(((hehe[t2][i] & mask1) == 0) ? " " : "█");
printf(((hehe[t2][i] & mask2) == 0) ? " " : "█");
printf(((hehe[t2][i] & mask3) == 0) ? " " : "█");
printf((i==1 || i==3)?" █ ":"   ");
printf(((hehe[t3][i] & mask1) == 0) ? " " : "█");
printf(((hehe[t3][i] & mask2) == 0) ? " " : "█");
printf(((hehe[t3][i] & mask3) == 0) ? " " : "█");
printf(" ");
printf(((hehe[t4][i] & mask1) == 0) ? " " : "█");
printf(((hehe[t4][i] & mask2) == 0) ? " " : "█");
printf(((hehe[t4][i] & mask3) == 0) ? " " : "█");
printf((i==1 || i==3)?" █ ":"   ");
printf(((hehe[t5][i] & mask1) == 0) ? " " : "█");
printf(((hehe[t5][i] & mask2) == 0) ? " " : "█");
printf(((hehe[t5][i] & mask3) == 0) ? " " : "█");
printf(" ");
printf(((hehe[t6][i] & mask1) == 0) ? " " : "█");
printf(((hehe[t6][i] & mask2) == 0) ? " " : "█");
printf(((hehe[t6][i] & mask3) == 0) ? " " : "█");
printf("\n");
}
fflush(stderr);
system("sleep 1");
system("clear");
}

return 0;
}```

0

@中山野鬼 来看下.

好像你问题想的太多了.  来调整下心情.

0

0

没有人来看下吗... ?

.. c来做  打印格式就是诸如:

0

THANKS .. 说的很好.
0

0