cterminalnewlineptybackspace

Can backspace escape cancel a new-line escape?


I'm working with ubuntu. Code:

printf("Hello\n\b world");

I get on terminal:

Hello
 world

Why does backspace not cancel the \n? Is there a hierarchy in chars?

How can I delete special chars?


Solution

  • Your question goes beyond the scope of the C language: printf("Hello\n\b world"); outputs the bytes from the format string, possibly translated according to the text mode handling of newlines:

    If the standard output is directed to a file, the file will contain the translation of the newline and a backspace (0x08 on most systems).

    If the standard output goes to a terminal, the handling of the backspace special character is outside the program's control: the terminal (hardware, virtual, local or remote...) will perform its task as programmed and configured... Most terminals move the cursor left one position on whatever display they control, some erase the character at that position. If the cursor is already at column 1, it is again system dependent whether backspace moves the cursor back to the end of the previous line, whatever that means. Many systems don't do that and keep the cursor at column 1. This seems consistent with the behavior you observe.