How can I prevent a given app from creating a newline (‘\n’) after I request user input in C?
I’d like something like:
Type a number
Number: 3x10 = 30
The “x10 = 30” is added after the user inputs the number.. The problem is I can’t do it on the same line (and I’d like to do it).
Can anyone help me?
As KillianDS said, most terminals buffer input automatically so you have to tell the terminal interface that you want raw/unbuffered input. Unfortunately, the way to do this will vary between most systems.
On UN*X systems, check out the
sttycommand (e.g.stty rawto set unbuffered andstty saneto go back to normal, these can be called viasystemor theexeclfamily). You could also use thetcsetattrcommand from thetermiosinterface.