0

I'm trying to implement a loop that is exited solely by pressing the 'q' key, how do I go about it.

This is for a shell I'm making, I've tried various input methods like getchar(), getch() and the expanded code of kbhit() {as kbhit() is not available in linux.}

The recurring fault I've been getting is that each time the loop runs an iteration, any of the input functions HALTS the loop execution and waits for the user input. Here, I'm trying to exit the loop if and when the 'q' key is pressed.

Thanks in Advance :)

  • look at ncurses – Support Ukraine Aug 23 '19 at 16:54
  • Sounds like your problem is in two parts: (1) Read characters immediately (without waiting for a newline or anything), and (2) implement a loop that reads characters, processing certain ones but breaking out when it reads a `q`. It's not clear which part you're having trouble with. I suggest writing a smaller problem that does nothing but part (1), printing each character immediately as it's received. Once you're sure you can do that, then try to write the loop for (2). – Steve Summit Aug 23 '19 at 17:50
  • In any case, you won't get answers or any detailed help unless you can post a small but self-contained version of your program here for people to actually see. – Steve Summit Aug 23 '19 at 17:52
  • Sure, I'll do that. Thanks :) – Maverick139 Aug 23 '19 at 19:19

0 Answers0