Making stdin non-blocking

后端 未结 4 1126
情深已故
情深已故 2020-12-18 07:37

I have an exercise where I am required to print a file slowly (1 second intervals) until the file ends, unless the user types a character.

So far, the program output

4条回答
  •  余生分开走
    2020-12-18 08:37

    You'd want to make your program multithreaded. Create a thread that prints out the file every 1 second interval, and your main thread would be getting input from stdin, then signal the other thread to stop printing whenever you get the input

提交回复
热议问题