Fedora Linux Support Community & Resources Center
  #1  
Old 17th November 2011, 02:09 AM
JoeNapoleon Offline
Registered User
 
Join Date: Oct 2011
Location: Wuhan , China
Posts: 22
linuxfirefox
a C program problem

How are you.
in the C program,I tested it, but the result doesn't show the character '\b' for backspace, what's the problem?
# vim countwords.c
# gcc countwords.c
#./a.out

Thank you very much.
Code:
#include <stdio.h>

#define ESC_CHAR '\\'

int main(void)
{
  int c;

  while((c = getchar()) != EOF)
  {
    switch(c)
    {
      case '\b':
        putchar(ESC_CHAR);
        putchar('b');
        break;
      case '\t':
        putchar(ESC_CHAR);
        putchar('t');
        break;
      case ESC_CHAR:
        putchar(ESC_CHAR);
        putchar(ESC_CHAR);
        break;
      default:
        putchar(c);
        break;
    }
  }
  return 0;
}

Last edited by JoeNapoleon; 17th November 2011 at 03:03 AM.
Reply With Quote
  #2  
Old 17th November 2011, 03:58 AM
jpollard Offline
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,105
linuxfedorafirefox
Re: a C program problem

I think it will depend on your input.

Since you are reading stdin, which is buffered, the backspace (^H or \b) will be consumed by the terminal driver since it, by default, processes it automatically - Lookup the difference between "raw" mode and "cooked", though that may be a bit old nomenclature.

See the manpage on "stty", which will let you change the mode (though getting commands to work gets tricky afterwards - use Control N for the end of the line, and try not make any typos - you can't erase them...)
Reply With Quote
Reply

Tags
problem, program

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem making a program leonardevens Using Fedora 3 10th March 2011 08:22 PM
Problem with program! chilavert1 Using Fedora 11 27th February 2009 12:21 PM
problem compiling c program popey Using Fedora 2 30th May 2008 06:48 PM
kde program crash problem tgbzsq Using Fedora 31 3rd April 2008 07:53 AM
Program c++ problem. Stevenisme Programming & Packaging 5 21st September 2005 03:00 PM


Current GMT-time: 05:59 (Thursday, 23-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat