Re: help with a program
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Fri, 14 Mar 2008 09:59:16 -0700
Richard Heathfield <rjh@xxxxxxxxxxxxxxx> writes:
broli said:[...]
This appears on page number 20 of K & R 2 exercise number 1-10
<snip>
The program compiles successfully but when I execute the program it
seems that it can't handle backspaces( '\b' character). The program
works fine when it encounters thet tabs and backslashes. Can some one
please tell me what is wrong here ?
Nothing!
The problem is that your shell is interpreting the backspace for you - so
the program never gets to see it. But you can still test the code easily
enough, by writing a file containing backspaces, and piping that file
through your code.
A small system-specific quibble: It's probably not the shell that's
interpreting the backspaces. When the program is reading input, the
shell isn't even running; it's suspended, waiting for the program to
terminate. On a Unix-like system, it's the terminal code (there's
probably a more accurate term for it) that processes certain control
characters, the ways in which it does so can be affected by the "stty"
command.
But it's pretty much the same idea.
One feature of the tty handling on Unix-like system is that there's
generally a way to pass through literal control characters. By
default, typing control-V causes the next character to be interpreted
literally. This might not work in all circumstances, and is unlikely
to work on non-Unix-like systems, but where it does work it's a good
way to exercise this program.
--
Keith Thompson (The_Other_Keith) <kst-u@xxxxxxx>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- References:
- help with a program
- From: broli
- Re: help with a program
- From: Richard Heathfield
- help with a program
- Prev by Date: Re: Variable length argument list - 32 / 64 bit problem?
- Next by Date: Re: Declared global variable isn't being seen by main.
- Previous by thread: Re: help with a program
- Next by thread: Re: help with a program
- Index(es):