f



hello world

Hi,

When writing the hello world program I insert \b in various locations
in the sentence.It works(making backspace) except when inserting
it after world\b.It dose not work.
Printf("hello, world\b")
Why?

Surena.
0
2/28/2004 8:55:53 PM
comp.lang.c 30657 articles. 5 followers. spinoza1111 (3246) is leader. Post Follow

5 Replies
442 Views

Similar Articles

[PageSpeed] 50

surena_abari@yahoo.com (surena abari) writes:

> When writing the hello world program I insert \b in various locations
> in the sentence.It works(making backspace) except when inserting
> it after world\b.It dose not work.
> Printf("hello, world\b")

What actually gets displayed?  This should display "hello,
world".  Perhaps you are unaware of what \b is supposed to mean
for a display device:

     \b (backspace) Moves the active position to the previous
         position on the current line. If the active position is
         at the initial position of a line, the behavior of the
         display device is unspecified.
-- 
"When in doubt, treat ``feature'' as a pejorative.
 (Think of a hundred-bladed Swiss army knife.)"
--Kernighan and Plauger, _Software Tools_
0
blp (3955)
2/28/2004 9:07:36 PM
On 28 Feb 2004 12:55:53 -0800, surena_abari@yahoo.com (surena abari)
wrote:

>Hi,
>
>When writing the hello world program I insert \b in various locations
>in the sentence.It works(making backspace) except when inserting
>it after world\b.It dose not work.
>Printf("hello, world\b")
>Why?
>
What makes you think it doesn't work?  What do expect to be different
with the \b in the string than without the \b?  Remember, the
backspace need not be destructive.

If you are using a windows system, look very carefully at the
placement of the cursor.  It should be under the d.  Then remove the
\b and try again.  It should be to the right of the d.


<<Remove the del for email>>
0
schwarzb (661)
2/28/2004 11:26:25 PM
Barry Schwarz <schwarzb@deloz.net> wrote in message news:<c1r831$qrv$3@216.39.134.19>...
need not be destructive.
> 
> If you are using a windows system, look very carefully at the
> placement of the cursor.  It should be under the d.  Then remove the
> \b and try again.  It should be to the right of the d.

Thanks for explaining the meaning of \b for me.
I have similar problems with other escape characters.
But I think this group it is not the proper place to
ask this questions as they are not related to C.
So would you please give me a reference(book or website)
that gives me the exact meaning of these characters?

Surena.
0
2/29/2004 11:18:45 PM
surena_abari@yahoo.com (surena abari) writes:

> Thanks for explaining the meaning of \b for me.
> I have similar problems with other escape characters.
> But I think this group it is not the proper place to
> ask this questions as they are not related to C.
> So would you please give me a reference(book or website)
> that gives me the exact meaning of these characters?

Here is what the C standard says about them:

2 Alphabetic escape sequences representing nongraphic characters
     in the execution character set are intended to produce
     actions on display devices as follows:

     \a (alert) Produces an audible or visible alert without
     changing the active position.

     \b (backspace) Moves the active position to the previous
         position on the current line. If the active position is
         at the initial position of a line, the behavior of the
         display device is unspecified.

     \f (form feed) Moves the active position to the initial
         position at the start of the next logical page.

     \n (new line) Moves the active position to the initial
     position of the next line.

     \r (carriage return) Moves the active position to the
     initial position of the current line.

     \t (horizontal tab) Moves the active position to the next
         horizontal tabulation position on the current line. If
         the active position is at or past the last defined
         horizontal tabulation position, the behavior of the
         display device is unspecified.

     \v (vertical tab) Moves the active position to the initial
         position of the next vertical tabulation position. If
         the active position is at or past the last defined
         vertical tabulation position, the behavior of the
         display device is unspecified.
0
blp (3955)
2/29/2004 11:25:59 PM
In <5c36e6b3.0402281255.47f0aa4f@posting.google.com> surena_abari@yahoo.com (surena abari) writes:

>When writing the hello world program I insert \b in various locations
>in the sentence.It works(making backspace) except when inserting
>it after world\b.It dose not work.
>Printf("hello, world\b")
>Why?

You're confusing the effect of pressing the Backspace key on your console
with the effect of the ASCII BS character itself.

When you press Backspace, on a console using or emulating a glass TTY 
device, the computer typically echoes back the BS, space, BS sequence,
effectively erasing the last character typed before BS.  That wouldn't
be particularly effective on a real TTY device, so you'd get a different
reaction from the computer, if you made it aware that your console is
some form of serial printer.

Also beware of "orphan" CR characters, i.e. characters that were, once,
part of a CR+LF pair, but the programmer has inadvertently removed the
LF only (usually because he was unaware of the presence of the CR).
If you have such a character in the middle of a line, the output may be
different from your expectations and the reason quite elusive.

Dan
-- 
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de
0
Dan.Pop (3615)
3/1/2004 4:28:21 PM
Reply: