程序这样写有很漏洞,不过满足你的要求够了。
#include <process.h>
/* _beginthread, _endthread */
#include <time.h>
#include <conio.h>
int returnflag = 0;
void CheckTime(void *p)
{
double bgn,end;
bgn = end = clock();
while(end-bgn<=5000)end=clock();
returnflag=1;
}
void CheckKey(void *p)
{
if(getch())returnflag=1;
}
void main()
{
_beginthread( CheckTime, 0, NULL );
_beginthread( CheckKey, 0, NULL );
while(!returnflag);
}