C exit from infinite loop on keypress

前端 未结 5 984
囚心锁ツ
囚心锁ツ 2020-12-10 05:47

How can I exit from an infinite loop, when a key is pressed? Currently I\'m using getch, but it will start blocking my loop as soon, as there is no more input to read.

5条回答
  •  盖世英雄少女心
    2020-12-10 06:02

    If you are using getch() from conio.h anyway, try to use kbhit() instead. Note that both getch() and kbhit() - conio.h, in fact - are not standard C.

提交回复
热议问题