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 ?
cout << "\a"; In Xcode, After compiling, you have to run the executable by hand to hear the beep.
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;
}
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With