B*****n 发帖数: 498 | 1 现在在算一个程序
要很长时间,而且是不停的在递规调用一个函数
过去,我就设定调用若干次以后停止,或者算了若干时间以后停止
但是这样有时候结果的精度不是很好
因为在算之前,我也不能知道应该算多少次,或者需要多少时间
请问怎么在这个函数里面接受键盘的输入,
比方说我按下A这个按键
程序就结束调用,输出结果?
如果我不按,那就一直算下去。
谢谢! |
y****i 发帖数: 156 | 2 kbhit: check keyboard input
getch: get the key.
You can find help in MSDN or turboc C
// MSDN example
/* KBHIT.C: This program loops until the user
* presses a key. If _kbhit returns nonzero, a
* keystroke is waiting in the buffer. The program
* can call _getch or _getche to get the keystroke.
*/
#include
#include
void main( void )
{
/* Display message until key is pressed. */
while( !_kbhit() )
_cputs( "Hit me!! " );
/* Use _getch to throw key away. */
prin
【在 B*****n 的大作中提到】 : 现在在算一个程序 : 要很长时间,而且是不停的在递规调用一个函数 : 过去,我就设定调用若干次以后停止,或者算了若干时间以后停止 : 但是这样有时候结果的精度不是很好 : 因为在算之前,我也不能知道应该算多少次,或者需要多少时间 : 请问怎么在这个函数里面接受键盘的输入, : 比方说我按下A这个按键 : 程序就结束调用,输出结果? : 如果我不按,那就一直算下去。 : 谢谢!
|
B*****n 发帖数: 498 | 3 This is exactly what I want, thank you so much!
【在 y****i 的大作中提到】 : kbhit: check keyboard input : getch: get the key. : You can find help in MSDN or turboc C : // MSDN example : /* KBHIT.C: This program loops until the user : * presses a key. If _kbhit returns nonzero, a : * keystroke is waiting in the buffer. The program : * can call _getch or _getche to get the keystroke. : */ : #include
|