+ 1

What is the of \b (backspace) in c.

"helloa" and "hello\ba" for both the output is same.In "hello\ba" the cursor move backwards but 'a' is printed next to 'o'? Explain it with a good example.

24th Dec 2016, 3:55 PM
rahul
rahul - avatar
3 Antworten
+ 6
\b by itself only moves the cursor.The usual way of erasing the last character on the console is to use the sequence "\b \b". This moves the cursor one space backwards, and prints a whitespace to erase the character, and backspaces again so that new output start at the old position.
24th Dec 2016, 4:04 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
Hi Rahul, you asked me to look at this post. I would not repeat me because this request is linked to your \n \r question. In printing system the \b command moves the head of a dot matrix printer backwards to the last character printed. This command is used to get a bold style, in fact it is used to print two or three times the same character marking it bolder on the paper. In text console programming the \b command is used to move backwards the cursor. I use it when asking a character like y/n and if the user press another key I would not accept it (deleting the entry and waiting for another entry).
24th Dec 2016, 5:22 PM
Michael Isac Girardi
Michael Isac Girardi - avatar
+ 2
It seems like the behavior depends on the terminal. Usually it's non-destructive (so: left arrow key) and the next character is typeover instead of insert (so you'd expect "hella" and NOT "helloa"). http://stackoverflow.com/questions/6792812/the-backspace-escape-character-b-in-c-unexpected-behavior You're probably going to have to explain this as it refers to your terminal.
24th Dec 2016, 5:35 PM
Kirk Schafer
Kirk Schafer - avatar