C语言控制台的数字时钟

转自:http://hi.baidu.com/csxwczj/item/68cd6e0f056da6eaf55ba67f

/*TC2.0编译*/
#include <time.h>
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <bios.h>
void time_box(int start_x,int start_y)                                //时间框体,用于在控制台指定坐标显示时间
{
textbackground(YELLOW);
textcolor(RED);
window(start_x,start_y,start_x+7,start_y);
clrscr();
}
void dis_time(unsigned long t,int box_x,int box_y)         //输出控制台时间显示
{
struct tm *ts;
textbackground(WHITE);
clrscr();
ts=localtime(&t);
time_box(box_x,box_y);
printf("%02d:%02d:%02d",ts->tm_hour,ts->tm_min,ts->tm_sec);
window(1,1,80,25);
textbackground(0);
}
void no_cursor(void)                                                //调用中断隐藏文本光标
{
union REGS r;
r.h.ah=1;
r.h.ch=32;
int86(0x10,&r,&r);
}
void clr_kb_buf(void)                                             //调用中断清除键盘缓冲区
{
union REGS r;
r.h.ah=0x0c;
int86(0x21,&r,&r);
}
int main(void)                                                         //主函数
{
int box_x=time(0)%72+1,box_y=time(0)%25+1;                       //以时间为种子,产生时间框的起始坐标
unsigned long t;
textbackground(RED);
clrscr();
no_cursor();                                                         //文本光标隐藏
while(1)                                                               //无限循环,主要算法在这一个死循环内展开
{
while(time(0)==t)
{
unsigned int key=bioskey(1);                            //调用BOISKEY函数1号功能,判断是否有键按下
if(key==0x011b)                                             
exit(0);                                //若按下的是ESC键(扫描码0x011b)退出程序
if(key)
clr_kb_buf();                      //有键按下但不是ESC,清除键盘缓冲区,这一步是必要的,其效果如何请把这一语句注释掉便可知晓
}
t=time(0);
dis_time(t,box_x,box_y);          //显示时间
}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值