2

I don't know why \a is not working. My code is working and displays in terminal. My code:

#include <stdio.h>

int main()
{
    printf("hello world\a");
    return 0;
}

My IDE: Visual Studio Code

My Compiler: Mingw gcc

Acorn
  • 24,970
  • 5
  • 40
  • 69

1 Answers1

1

The behavior of \a depends on the environment/terminal you use.

My guess is that Windows does not implement it or perhaps it is disabled for some reason. There is not much you can do unless you use platform-specific APIs that play a specific sound.

See How to make a Beep sound in C on Windows?

Acorn
  • 24,970
  • 5
  • 40
  • 69
  • 1
    conhost.exe (which is the console that cmd and powershell connects to) does support beep. Try echo "\`a", `echo [char]7` or `cmd /c "echo $([char]7)"` in powershell and you'll hear a sound. Or type `echo ` then Ctrl+G or Alt+7 in cmd and you'll see the same effect – phuclv Aug 13 '20 at 04:15
  • @phuclv Thanks for the details! It has been a while since I used Windows. I recall having heard the beep many years ago over there, but I was not sure if it was from the terminal or if it was still enabled by default. In any case, relying on `\a` to make the sound is not a great idea, so I decided to link the other question. – Acorn Aug 13 '20 at 04:32
  • 1
    I don't think modern motherboards come with a buzzer, so modern versions of Windows will use speakers instead. Too bad, the buzzer era is some major nostalgia. (Real computers should sound like BEEP beep-beep-beep-BEEP BEEP when booting.) – Lundin Aug 13 '20 at 11:53