This is because you are actually entering two characters: 'a' and a new line. In addition, since the terminal is usually buffered by line, your program will only see your input after you click on a new line. It will also be useful to enter a longer line of text.
If you want to change this behavior, you have two options: reading whole lines (i.e. all characters to a new line or the end of the file) or switching the terminal to non-canonical mode. The latter makes sense if you are working on an interactive terminal application, such as a text editor. See termios manpage for more details. In short, you will want to set the MIN and TIME values ββto zero in order to read data from the terminal immediately after receiving the data. If you go this route, make sure that you turn off the terminal when exiting, including due to the reception of a signal.
fflush() affects the output, not the input.
source share