Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to produce beep sound using "\a" escape character?

Tags:

c

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

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

Can you tell me how to use \a for producing beep sound using C program ?

like image 409
Parikshita Avatar asked Oct 02 '10 12:10

Parikshita


People also ask

How do you add a beeping sound in C++?

cout << "\a"; In Xcode, After compiling, you have to run the executable by hand to hear the beep.


2 Answers

The only thing wrong (half wrong) with your program is main signature.

To be 100% portable it should be int main(void) or int main(int argc, char **argv) or equivalent: int main() is not equivalent.


And I'd print a '\n' too, or flush the output buffer rather than relying on the runtime flushing all buffers for me automatically, but your program should sound the bell as it is. If it doesn't the problem is elsewhere, not with C.

#include <stdio.h>
int main(void)
{
    printf("\a\n");
    return 0;
}
like image 173
pmg Avatar answered Sep 18 '22 06:09

pmg


i usually use another way to get the beep sound it works 100% on windows 7.

    int x=7; //7 is beep sound other numbers may show emoji and characters
    printf("%c",x);
like image 30
user332422 Avatar answered Sep 20 '22 06:09

user332422