Thread: Ascii list

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    7

    Ascii list

    I wrote a simple program to display ASCII code but when I run it, some of the ASCII stuffs up and my computer makes a loud beep, does anyone know why?
    thanks

  2. #2
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Certain characters, when printed, cause a beeping sound (beep chars). I'd imagine those music lyric icons do.

    Beep beep!

    I'm sure there's some historical reason for this. However I'm more interested in how to easily disable it, other than filtering strings of course.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The beep is \b typically, and IIRC, it's 8. The music notes are just characters, not sounds. 10 is \n, 13 is \r. You might take a look at asciitable.com


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    7
    lol thanks, no wonder... so it's actually meant to 'screw' up and appear like that!

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by quzah
    The beep is \b typically, and IIRC, it's 8.
    I thought that \b was for backspace, and \a was for alert, the latter typically resulting in a beep.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    That's it. Been a long time since I've needed either.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by C++ student View Post
    lol thanks, no wonder... so it's actually meant to 'screw' up and appear like that!
    It might be a good idea to filter out all non-printable, non-space characters. For one thing, their appearance on the display isn't really ASCII, but whatever the OS and current code-page maps them to. For another, they can obviously lead to some weird effects (such as the one you encountered). I'd recommend something like this:

    Code:
    #include <iostream>
    #include <iomanip>
    
    int main( void )
    {
        using namespace 
            std;
        for( int ch = 0; ch < 128; ++ch )
        {
            cout << setw( 3 ) << dec << ch << " : ";
            if( isprint( ch ) && !isspace( ch ) )
                cout << "'" << char( ch ) << "'";
            else
                cout << "0x" << hex << ch;
            cout << endl;    
        }
        return 0;
    }

  8. #8
    Registered User
    Join Date
    Sep 2009
    Posts
    7
    thanks for the code sebastiani, i'll try investigating it :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 AM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  4. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 05:20 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM