|
可以在控制台下动态的显示时间 ... 定位于右上角 , 使用很简单 保存代码
- gcc -o showtime showtime.c
复制代码
代码如下 :
- /* file: showtime.c */
- #include <stdio.h>
- #include <time.h>
- #define ESC '\033'
- #define MOVETO "\033[%d;%d;H"
- #define SAVE "\0337"
- #define RESTORE "%c8",ESC
- #define ROW 1
- #define COL 50
- main()
- {
- time_t i;
- char * atime;
- while (1) {
- time(&i);
- atime = asctime(localtime(&i));
- atime[strlen(atime)-1] = '\0';
- printf(SAVE);
- printf(MOVETO,ROW,COL);
- printf(" +--------------------------+ ");
- printf(MOVETO,ROW+1,COL);
- printf(" + %s +",atime);
- printf(MOVETO,ROW+2,COL);
- printf(" +--------------------------+ ");
- printf(MOVETO,ROW+3,COL);
- printf(" ");
- printf(RESTORE);
- fflush(stdout); /**/
- sleep(1);
- }
- }
复制代码
附件是效果图 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|