How to go to the previous line in a C code

后端 未结 7 2021
渐次进展
渐次进展 2021-01-14 11:14

If for the following code:

printf(\"HEllo\\n\");    // do not change this line.
printf(\"\\b\\bworld\");

I need an output: Helloworld (In a

相关标签:
7条回答
  • 2021-01-14 12:04

    It is because '\b' is a terminal escape code... (sans the 'escape' of course ;-)

    so it only modifies what you see on the terminal. That is, the terminal adjusts its display to respond to the backspace code, even though it received everything prior to it. A file also receives everything, including the backspace code, but it is not a tty device so the file's content is not modified; it keeps everything you send to it.

    If printing an extra blank is a problem, then you should code some extra logic to print the trailing blank on every output except the last.

    Reference This is in reference to files but maybe same idea applies. You might want to check out this link there is a very detailed explanation that most probably answers your question.

    0 讨论(0)
提交回复
热议问题