0

Is there any way to play the BEEP sound when I write the following program?

#include<stdio.h>
void main()
{printf("\a");
}

I tried running the program using the GCC compiler in Linux but it did not give any beep whereas when the program ran in the Windows Environment, it generated the system default beep.

Ali
  • 56,466
  • 29
  • 168
  • 265
Pranav Jituri
  • 823
  • 1
  • 11
  • 25
  • 3
    This has nothing whatsoever to do with the compiler. It's about what your hardware and terminal support. – mah Nov 16 '13 at 18:52
  • See http://unix.stackexchange.com/questions/1974/how-do-i-make-my-pc-speaker-beep – Remus Rusanu Nov 16 '13 at 18:54
  • Please replace whatever book told you to use `void main()`; it was written by someone who doesn't know the language very well. The correct definition is `int main(void)`. (`void main()` might happen to work, but it's neither portable nor correct.) – Keith Thompson Nov 16 '13 at 21:32
  • [toot](http://github.com/vareille/toot) is a cross-platform C file and command line tool that try to call several sound generators to produce the beep – renataflow Nov 11 '17 at 06:34

1 Answers1

0

The code is correct; the program generates a beep-signal. I suppose, that a beep signal switched off in your terminal. May be you have enabled visual-bell. In this case your terminal must blink.

Igor Chubin
  • 61,765
  • 13
  • 122
  • 144
  • Umm, I do no get any visual blinking of the Terminal in Ubuntu. Could you please tell me how to enable the beep sound in the Terminal then? – Pranav Jituri Nov 16 '13 at 18:56
  • 1
    @PranavJituri: It depends on the terminal-emulator. You can start for example xterm and enable visual bell in it (hold `ctrl` then click and drag the mouse wheel; you will see a menu, in that you must choose "Enable visual bell") – Igor Chubin Nov 16 '13 at 21:12