0

I am trying to do something like this

#include <conio.h>
#inlcude <iostream>

void getInput(){

   //while no input is given..
     while(!_getch()){ 
     printf("no input");
     }

   //as soon as input is given ('a', '1',...)
     printf("Input detected!");
}

i want to print "no input" over and over exept for when a key is pressed(then it should print "input detected")

but with this code it does not work because it will stop at _getch() and wait for input. how can i skip this part or how can i tell the while loop there was no input?

thank you :)

stimulate
  • 1,199
  • 1
  • 11
  • 30
  • Possible duplicate of [Why does getchar work like a buffer instead of working as expected in real-time](http://stackoverflow.com/questions/31561928/why-does-getchar-work-like-a-buffer-instead-of-working-as-expected-in-real-time) – Barmar Sep 01 '16 at 17:21
  • Have to use something platform specific or non-standard like [`_kbhit`](https://msdn.microsoft.com/en-us/library/58w7c94c.aspx). – Captain Obvlious Sep 01 '16 at 17:23

0 Answers0