backspace

This is a discussion on backspace within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { /*Write a program to copy its input to its ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Location
    Croatia
    Posts
    272

    backspace

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
         /*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.*/
           
         int a=0;
         
         while((a=getchar())!=EOF)
         {
             if(a=='\t')
             {
             putchar('\\');
             putchar('t');
             }
             
             else if(a=='\b')
             {
             putchar('\\');
             putchar('b');
             }
             
             else if(a=='\\')
             {
             putchar('\\');
             putchar('\\');
             }
         
             else
             putchar(a);
             
         }
         
           
      system("PAUSE");	
      return 0;
    }
    Anyways, just out of curiousity, i was wandering if there's a way to get backspace working - im using Dev-C++ compiler. I expected that backspace wasnt gonna work anyway, im just wandering what did the authors mean and how can u get it done.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If the input is in a file, then you can have a backspace character in the text file.

    If the input is typed in to the program, then you're in trouble -- you'd have to grab input directly, rather than waiting for the console to hand it to you.

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, 03:14 AM
  2. Meaning of backspace
    By PlanetCoder in forum C Programming
    Replies: 4
    Last Post: 06-05-2006, 03:34 AM
  3. ascii backspace, K&R book exercises
    By jjohhn in forum C Programming
    Replies: 10
    Last Post: 12-29-2005, 08:33 AM
  4. Richedit backspace character????
    By gbaker in forum Windows Programming
    Replies: 0
    Last Post: 08-12-2003, 12:38 PM
  5. Replies: 3
    Last Post: 11-30-2001, 07:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21