金港国际怡园:如何用C语言编写定时器程序?

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/26 09:10:23
最好能想MFC里面那样能中断响应
能不能通过硬件实现,例如8254计数?
好像也不一定要通过硬件实现,但要和主程序并行执行,要用线程实现

#include <stdio.h>
#include <time.h>

main()
{
clock_t start,end;
int n;
printf("How many seconds do you want to count? ");
scanf("%d",&n);
getchar();
clrscr();
start=end=clock();
while((n-(int)(end-start)/19)>=0&!kbhit())
{
printf("the time is: %d",n-(int)(end-start)/19);
sleep(1);
end=clock();
clrscr();
}
}