\b ?

G

Gernot Frisch

printf("<return>");
getchar();
printf("\b\b\b\b\b\b\b\b\b");

printf("Some new text");

output:

<return>
Some new text

What did I do wrong?
 
K

Karl Heinz Buchegger

Gernot said:
printf("<return>");
getchar();
printf("\b\b\b\b\b\b\b\b\b");

printf("Some new text");

output:

<return>
Some new text

What did I do wrong?

What did you expect?
 
K

Karl Heinz Buchegger

Gernot said:
That the "<return>" would be overwritten.

That cannot work.
Part of entering something with getchar() is pressing
return. Most systems immediatly echo the entered characters
(otherwise you wouldn't see what you have entered) thus
the <return> is echoed too, thus the cursor moves on to
the next line. Using backspace it nomally is not possible
to undo the effect of a <return>. Backspace usually works
in the same output line only.
 
G

Gernot Frisch

That cannot work.
Part of entering something with getchar() is pressing
return. Most systems immediatly echo the entered characters
(otherwise you wouldn't see what you have entered) thus
the <return> is echoed too, thus the cursor moves on to
the next line. Using backspace it nomally is not possible
to undo the effect of a <return>. Backspace usually works
in the same output line only.

Good explaination. How to solve it? I use the getchar() to wait for
reading the message, then continue after any key. So I wrote "any" on
my return key... ;)
-Gernot
 
K

Karl Heinz Buchegger

Gernot said:
Good explaination. How to solve it?

Not using getchar()
You need some non standard input function which does
not echo anything to the screen and thus does not interfere
with your own cursor control.
If you are programming for DOS/Windows, _getch() from conio.h
would be a solution.
 
L

Leon Mergen

If you are programming for DOS/Windows, _getch() from conio.h
would be a solution.

.... and I believe ncurses provides this for linux, although this might
bring along a huge overhead.

Leon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,290
Messages
2,571,453
Members
48,129
Latest member
DianneCarn

Latest Threads

Top