Is it possible? Using regular scanf or getchar won't work because I have to press "enter" after entering the char.
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
You're approaching the domain of ncurses.
The input stream in C is buffered.
A buffer is a place where data is temporarily held until it is ready to be processed.
The buffer is flushed (emptied) when one of three things happens:
You're going to have to use facilities not included in the standard library in order to have that functionality.
Maybe
getch()
inconio.h
is what you need, but note that it's non-standard.It is not possible by using pure standard C. You will have to use a system-specific library like conio.h or the Windows API etc.
The streaming functionality is getting in the way. There may be an
fcntl
option to turn off the buffering. Or you may have better luck using the lower levelread
call.