We all know how to print a string one tab further with \t
printf ("Hello\tthere!\n");
which outputs:
Hello there!
What about printing one tab backwards? I know we can just use \r to start back from the beginning of the line, but there are situation when indentation is more complex than that, I am looking for something like \bt (if it existed) such that I could write:
printf ("Hello\tthere! \n\tHow\n\btare you?\n");
to get in output:
Hello there!
How
are you?
Edit
I am surprised by the amount and speed of replies here, and sometimes even by the uselessness of some comments, but only a few. What I am trying to achieve is of course more complex than this, it’s properly formatting an XML file to be easily readable. I wanted to be sure there wasn’t an easier way, the response confirmed there wasn’t thanks.
Edit 2
Sorry guys, you are right to vote down this question, first because I didn’t specify I was writing to a text file, secondly because I was assuming tabs could be “remembered” by the file handler. Sorry for wasting your time.
With printf you control how much tabbing is taking place explicitly. To back tab you would just use fewer tabs. From the example you provided it looks like you are expecting the tab level to be remembering, and have How indented farther than it really will be when printed. It would appear at the same tab stop as there! and are you?
Assuming with:
You are expecting to see:
Hello there! How are you?Then just don’t add the tab before are you? and you will get what you want. To get fewer tabs, just add fewer \t symbols to your printf. printf doesn’t have any memory of what tabbing has occurred before.