search

Home  >  Q&A  >  body text

How to non-block input in C language (check if stdin has content)

getchar, scanf, getch, these will block if the user does not input. What should I do if I don’t want to block?
I searched online and found that fcntl can be used in Linux, but not in Windows (you can use GetAsyncKeyState to check the keys, but you cannot know whether stdin has content)

我想大声告诉你我想大声告诉你2719 days ago1370

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-06-17 09:18:16

    There is ioctl on windwos that can be implemented, but this is just setting the attributes of the file descriptor. For non-blocking input, you still need to configure the corresponding API

    I found an example and I’m not sure if it’s what you want. The file descriptors used by socket and IO are the same

    set nonblock

    These things can all be found on Google. .

    reply
    0
  • Cancelreply