> I'd want to achieve the following effect during an input from terminal
> using readline in a C program:
>
> the user types something (the input line), and the input routine does
> not go to a new line, rather types something in response and only after
> this response the new line is executed.
>
> An example is the gforth output (the intended effect I want to achieve):
>
> 1 2 + . [ENTER] 3 ok
> _
>
> The user presses [ENTER] after last character (the dot), the system
> prints the answer (3), the ok label and only THEN goes to the new line.
There is no way to achieve this using standard C. One way to do
it on UNIX is to turn off character echo and echo the characters
after you read them (and only when you want to; don't echo the ENTER
which in your example messes up the line). However, you don't want
the user "typing blind" so they can't see if they type the wrong
character. Also, handling typing mistakes with such characters as
"backspace" is now up to you.
There is also no way in standard C to read characters one at a
time. Under UNIX, there are "cbreak" mode and "raw" mode.
The simplest way to invoke these is probably:
system("stty -echo cbreak");
It is left as an exercise for the reader to figure out how to
undo this before terminating the program.
Even within UNIX, there are several different methods of
using ioctl() to accomplish the same thing, which is faster
and does not require another process, but they are mutually
incompatible. Having a #ifinclude would be useful here.
If you wanted this to work on Windows, it might have a similar
function.