-2

I have tried to use the getch() function to meet my requirement but it did not work. What am I supposed to do if I want to call a function in an infinite for loop only when I press some key otherwise the loop keeps on running without calling the function?

CerebralCortexan
  • 299
  • 2
  • 17

1 Answers1

0

You can use something like this _kbhit.

You can also Refer this a stackoverflow answer. _kbhit returns a nonzero value if a key has been pressed. Otherwise, it returns 0. You can use this to enter your function optionally.

Please specify your operating System. This is for Windows.

For Unix like Operating System refer this.

And If you are referring to and embedded System, Then please elaborate your question and add more details.