Thread: Printing a backspace

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    3

    Printing a backspace

    Hi, I'm trying to code the functionality of a cellphone keyboard, where have to press key '2' three times in order to get letter 'C' and so on. Every time the user types a character it is printed to the screen using putchar(). What I cant do is print a backspace, so that the the cursor goes back one space and the letter on that space can be deleted. I tought if I used "putchar(0x08)" it would work, but it doesn't, when I do that the cursor goes forward. I'm using a switch loop to see what key the user pressed, here's the code for the case when the backspace key (B) is pressed

    Code:
    case 'B':  	if (pos > 0) {
    		        putchar(0x08);
    			pos --;
    			count = 0;
    		}
    		break;
    But as i said, it just prints a space after the last input, instead of going back. So I would appreciate any help on how to do this. Also, I'm trying not to use gotoxy to go back and erase characters, so that the function can be used no mather what the coordinates are.

    Tnx for any help.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I guess the questions are
    (1) what system (compiler, etc.) are you using?
    (2) why aren't you using the backspace character \b?

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    3
    Quote Originally Posted by tabstop View Post
    (1) what system (compiler, etc.) are you using?
    First of all, tnx for the reply, second:
    I'm using Turbo C++ versión 3.0 but the program I'm writing is a .C file.

    Quote Originally Posted by tabstop View Post
    (2) why aren't you using the backspace character \b?
    The same thing happens if use that, you mean like :

    Code:
    case 'B':  	if (pos > 0) {
    				putchar('\b');
    				pos --;
    				count = 0;
    		}
    		break;
    It still just prints a space.
    Last edited by Leima; 03-21-2009 at 05:29 PM. Reason: i made a mistake

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Then perhaps Turbo is somewhat more broken than I thought. Using gcc-mingw, the code
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void) {
    
        putchar('T');
        putchar('h');
        putchar('i');
        putchar('s');
        putchar('\b');
        putchar('n');
        return 0;
    }
    prints Thin as you would want. If it doesn't for you, then I would suggest getting a real compiler (many good ones are available for free, including gcc-mingw (as in Code::Blocks) or MS Visual Studio Express).

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    3
    I tested that code and it actually does print "Thin", so I guess the compiler's good. It must be something I'm not doing right so I'll check that now.

    Tnx for your help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# Printing Problem
    By silverlight001 in forum C# Programming
    Replies: 0
    Last Post: 03-23-2009, 01:13 AM
  2. telnet server, how to program a backspace
    By Mastermosley in forum C# Programming
    Replies: 5
    Last Post: 03-22-2009, 02:14 AM
  3. generic printing preferences dialog box
    By stanlvw in forum Windows Programming
    Replies: 8
    Last Post: 06-27-2008, 02:20 AM
  4. printing data to a file
    By coralreef in forum C Programming
    Replies: 3
    Last Post: 11-02-2006, 08:10 PM
  5. need help relating printing?
    By omarlodhi in forum Linux Programming
    Replies: 0
    Last Post: 03-03-2006, 04:46 AM