How to non-block input in C language (check if stdin has content)
我想大声告诉你
我想大声告诉你 2017-06-17 09:16:16
0
1
1369

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)

我想大声告诉你
我想大声告诉你

reply all(1)
伊谢尔伦

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. .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template