Thread: Meaning of backspace

  1. #1
    Registered User
    Join Date
    Jun 2006

    Meaning of backspace

    Exercise 1-10 in K&R's book states:

    Write a program to copy its input to its output, replacing each tab by \t, each backspace by \b, and each backslash by \\. This makes tabs and backspaces visible in an unambiguous way.
    My question is: How can the input have a backspace?

    Thanks in advance.

  2. #2
    Awesomefaceradcore bivhitscar's Avatar
    Join Date
    Apr 2006
    Melbourne, Australia
    Well, if you scan each input character using getchar(), then you should be able to detect any backspace pressed ( I think... ).

    Well, that doesn't work on windows xp and dev-c++
    Last edited by bivhitscar; 06-04-2006 at 03:36 AM.
    it's ironic considerate rarity patron of love higher knowledge engulfs me...

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > My question is: How can the input have a backspace?
    That might depend on your OS and compiler.

    Most stdin streams are "cooked" in some way, so things like backspace and delete are handled by the terminal driver, so the user can edit the line they type in before pressing return.
    So any backspace they type gets interpreted by the driver rather than your program.

    Exactly how you get past that depends on your circumstances.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Jun 2006
    ... There is a byte notation that will tell you what character is which, im sure backspace is in ther somwhere, meaning you could probably do a for loop and scan it while copying or editing the input to see... but i agree, you cant show a backspace in past time, only real time... good luck on this one...

  5. #5
    Registered User
    Join Date
    Mar 2006
    Direct input functions like getch() will read backspaces. Backspace is ASCII 0x08.
    #include <stdio.h>
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. telnet server, how to program a backspace
    By Mastermosley in forum C# Programming
    Replies: 5
    Last Post: 03-22-2009, 02:14 AM
  2. ascii backspace, K&R book exercises
    By jjohhn in forum C Programming
    Replies: 10
    Last Post: 12-29-2005, 08:33 AM
  3. The Meaning of Life: A Trick Question?
    By chix/w/guns in forum A Brief History of
    Replies: 14
    Last Post: 07-12-2004, 07:53 PM
  4. Richedit backspace character????
    By gbaker in forum Windows Programming
    Replies: 0
    Last Post: 08-12-2003, 11:38 AM
  5. Replies: 3
    Last Post: 11-30-2001, 07:38 PM