Sunday 15 August 2010

Usage of \b and \r in C -


\ b and \ r rarely used in practice I just got to know that I misunderstood these two escape sequences. A simple test:

  printf ("foo \ bbar \ n");   

I hope this output will be for the FOP , because \ b will return a backspace to the cursor, and b < / Code> overwrites the second o , but instead it outputs: foobar

same \ r With:

  printf ("foo \ rbar \ n");   

I thought that \ r will move the cursor at the beginning of the current line, so bar to foo , so the final output should be bar . However, it actually outputs:

  foo bar    

characters will be sent directly in the same way as the built-in output device (in your case the terminal emulator).

This is dependent on the implementation of the terminal, so these characters are actually displayed. For example, a bell ( \ a ) can trigger a beep on some terminals, flashs on each other on the screen or it will be completely ignored. It all depends on how the terminal is configured.

No comments:

Post a Comment