Thread: This program sounds the bell!!!

  1. #1
    Registered User
    Join Date
    Aug 2010
    Location
    Dhaka, Bangladesh
    Posts
    16

    This program sounds the bell!!!

    The book I'm using gives an example as following:

    This program sounds the bell.

    Code:
    #include "stdio.h"
    int main()
    {
     printf("\a");
     return 0;
    }
    What does this program mean? Does this program mean that we can hear a ringing bell? I can't hear any ringing bell sound!!!
    Last edited by Sharifhs; 08-11-2010 at 12:03 AM. Reason: Added last line

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Sharifhs
    What does this program mean? Does this program mean that we can hear a ringing bell? I can't hear any ringing bell sound!
    It could be a beep, or something like that.
    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

  3. #3
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    IIRC, a is for for alert. Beeps are alerting. Something else that is alerting would be a valid replacement for a beep.

  4. #4
    Registered User
    Join Date
    Aug 2010
    Location
    Dhaka, Bangladesh
    Posts
    16
    Quote Originally Posted by laserlight View Post
    It could be a beep, or something like that.
    But I couldn't hear that!!!

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    It's undoubtedly platform dependant. Your platform probably does not choose to make any sound when printing that char. This is not surprising since the roots of that behaviour go back a good 20 years give or take, and most people do not run an OS anywhere near that old.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  6. #6
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    You could use this if you're on Windows: Beep Function (Windows)

  7. #7
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Maybe you have your speaker off or low volume?

  8. #8
    Registered User
    Join Date
    Aug 2010
    Location
    Dhaka, Bangladesh
    Posts
    16
    Quote Originally Posted by iMalc View Post
    It's undoubtedly platform dependant. Your platform probably does not choose to make any sound when printing that char.
    but it should display the beeping character(\a), isn't it? In my windows xp platform, either one is not working.

  9. #9
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    It probably uses the mobo speaker, so volume probably doesn't matter. Dos your computer have a speaker on it's mobo? I don't know a lot about hardware, but you probably do have one, I do on all my computers, and they're used by BIOS to communicate errors. Possibly it's broken?

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The '\a' is the mobo beep, which not all mobo's have. My last build, the beeper came in a small plastic bag, and you had to install it yourself.

    The board I'm on right now will beep, but will NOT beep the first time printf("\a"); is called. Second time and up, the beep will sound. This is with WindowsXP and using Turbo C.

    My "alert" or bell in a C program, is NOT the same sound as my Windows error sound. Control characters in C, are not printed - they may show their result on the console - like \b\b shows a backspace, but they are meant to DO something, not to be printed out, as displayed char's themselves.
    Last edited by Adak; 08-11-2010 at 06:31 AM.

  11. #11
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    See, Adak had to go back to an anchient compiler to get it to beep!
    This functionality is very old hat. Forget about getting it to do anything.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  12. #12
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    It works with MinGW GCC on Win7 x64. It's not a mobo beep though, Win7 emulates the mobo speakers and uses the normal speakers instead.

  13. #13
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Quote Originally Posted by iMalc View Post
    It's undoubtedly platform dependant. Your platform probably does not choose to make any sound when printing that char. This is not surprising since the roots of that behaviour go back a good 20 years give or take, and most people do not run an OS anywhere near that old.
    Probably closer to 50 years! I remember the ASR-33 (teletype) had a bell. '\a' translates to the ASCII character 007, so its definition is BEL.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

Tags for this Thread