love you to bits 21:用C语言编秒表的问题呀~在线等!

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 12:46:47
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
struct tm { int hours,minutes,seconds;};
void delay()
{ long int t;
for(t=1;t<=11128000;++t);

}

void update(struct tm *t)
{ (*t).seconds++;
if ((*t).seconds==60) {
(*t).seconds=0;
(*t).minutes++;
}
if ((*t).minutes==60) {
(*t).minutes=0;
(*t).hours++;
}
if((*t).hours==24) (*t).hours=0;
delay();
}
void display(struct tm *t)
{
system("cls");
printf("%d:",(*t).hours);
printf("%d:",(*t).minutes);
printf("%d\n",(*t).seconds);
printf("Now, press 'e' key to stop the clock...");
}

int main()
{ char m;
struct tm time;
time.hours=time.minutes=time.seconds=0;
printf("Now, press 's' key to begin the clock...\n");
m=getche();
if(m=='s'||m=='S')
for(;;) {
update(&time);
display(&time);}
else{ printf("Only 's' or 'S' can be inputed!!");}
getch();

}
这个程序要怎么让它实现按S就停止呢?急呀~~~~~~~~~在线等

int main()
{ char m;
struct tm time;
time.hours=time.minutes=time.seconds=0;
printf("Now, press 's' key to begin the clock...\n");
m=getch();
if(m=='s'||m=='S')
while(1)
{
while(!kbhit()) {
update(&time);
display(&time);}
m=getch();
if(m=='s'||m=='S')break;
else{ printf("Only 's' or 'S' can be inputed!!");}
}
}
把main函数改成这样看看行不行