How to produce beep sound using “\a” escape character?

前端 未结 6 1453
渐次进展
渐次进展 2021-01-04 06:24

If I write the following program, then there is no beep sound on running the code.

#include 
int main()
{ 
    printf(\"\\a\");
    return 0;
         


        
6条回答
  •  借酒劲吻你
    2021-01-04 06:50

    Please list your operating system, how did you run your code, and if your computer has a beeper.

    If you use Windows, maybe this Q&A How to make a Beep sound in C on Windows? would help you.

    If you use a GUI desktop Linux distro, terminal emulator like gnome-terminal or xfce4-terminal have a preference option bell to check. Then, make sure your speaker works.

    The code below works well for me:

    /* name: bell.c
     * run: gcc bell.c && ./a.out
     */
    
    #include 
    
    int main(void) {
        printf("\a");
        return 0;
    }
    

    By the way, your code is not the problem.

提交回复
热议问题