发新话题
 搜藏 打印 该页面添加到 Mister Wong

一个在终端显示时间嘀哒走的程序

一个在终端显示时间嘀哒走的程序

一个在终端显示时间嘀哒走的程序
复制内容到剪贴板
代码:
#include <stdio.h>
#include <time.h>
#include <unistd.h>

int main ()
{
        while (1) {
                time_t sec  = time(NULL);
                struct tm t = *localtime(&sec);

                printf("\x1b[2J");      /* clear screen and home cursor */
                printf("\x1b[31;40m");  /* red foreground, black background */
                printf("\x1b[11;29H");  /* moves cursor to line 11, column 29 */
                printf("+-----^--^-----+\n");
                printf("\x1b[12;29H");
                printf("|\t%02d:%02d:%02d:  |\n", t.tm_hour, t.tm_min, t.tm_sec);
                printf("\x1b[13;29H");
                printf("+-------V------+\n");
                sleep(1);
        }

        return 0;
}
/* reference: ANSI Escape Sequences
* compile:   gcc mytime.c -o mytime
* usage:     ./mytime
*/

本文由lili 发布于Linuxsky 论坛,网址:http://bbs.linuxsky.org/thread-4563-1-1.html

是故易有太极,是生两仪。两仪生四象,四象生八卦。

TOP

挺简单的 呵呵
技术研讨欢迎访问http://westsoftware.blog.163.com

TOP

发新话题