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

前端 未结 6 1485
渐次进展
渐次进展 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条回答
  •  旧时难觅i
    2021-01-04 06:59

    If you are using Windows, the Windows-versions making beep very different ways. Some of them enable that and working fine, but some windows versions don't. In some windows, it works just that case, if you have an internal motherboard speaker. But some other windows, it works fine without internal motherboard speaker, directly from sound-card (that would be nice!).

    If you are lucky, and using the appropriate windows-version, beep/Beep/printf("\a") will work (on internal speaker (if you have), or best case via soundcard). But if you are using an other windows version, it will not work. If in your computer it's okay, your friend's / family member's pc will silent, and he/she will think that you wrote a bad program :-D but not.

    My advice, that you should use a library for audio. It's simple, cross-platform, and it will be working always all times all computers etc. For example, Allegro_v4, Allegro_v5, SDL (Simple DirectMedia Layer), or something like that. These librarys works fine with OpenGL / DirectX, and with these librarys, you can load images, play videos, and things like that. Native OpenGL / GLUT / DirectX can't do things like that.

提交回复
热议问题