How to make a C routine run and do not stop until I execute a command?

Asked

Viewed 118 times

2

Good evening, I’d like to do a C routine like this: Let’s say I have a loop that keeps printing the letter 'a' and while I don’t type anything it keeps printing, but the moment I press 'c' for example, it starts printing the letter 'c' and keeps printing while I don’t type anything. That’s more or less what I’d like but I’m not getting to reproduce it. Thank you!

1 answer

1

You can use the kbhit:

do
{
  puts("c");
} while(!kbhit());

The only problem is that it doesn’t work on all compilers.

examples of use on other compilers: examples

Browser other questions tagged

You are not signed in. Login or sign up in order to post.