Breaking infinite loop.
-
Hi, I need to break the infinite loop by pressing some key, 'x' for example. How can I do it in C or C++ for console application? Thanks.
Could you please explain what you are trying archive? Do you want to check whether the 'x' key is pressed, in between your loop? In that case check this - Non-Blocking input in Console Applications[^]. Just ignore my reply. Mark's idea is cool! :D Regards, Jijo.
_____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
modified on Thursday, January 1, 2009 2:13 PM
-
Hi, I need to break the infinite loop by pressing some key, 'x' for example. How can I do it in C or C++ for console application? Thanks.
Just one way...
#include <conio.h>
...
int ch = 0;
do
{
// ...do something useful...if (\_kbhit()) { ch = \_getch(); ch = toupper(ch); } } while (ch != 'X');
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Just one way...
#include <conio.h>
...
int ch = 0;
do
{
// ...do something useful...if (\_kbhit()) { ch = \_getch(); ch = toupper(ch); } } while (ch != 'X');
Mark Salsbery Microsoft MVP - Visual C++ :java:
Mark, the
_kbhit()
is really cool and my 5 points for you! :) I was totally focused on "non-blocking input in C++
" while searching. :sigh: Regards, Jijo._____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
-
Mark, the
_kbhit()
is really cool and my 5 points for you! :) I was totally focused on "non-blocking input in C++
" while searching. :sigh: Regards, Jijo._____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
Heh thanks. I thought for sure there was a single non-blocking function, but I only seem to be able to find it when I WANT the blocking function and I forget what it is :-D If anyone knows, please refresh my memory :) Cheers, Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: