Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my laptop, I've tried to use the beep escape sequence (i.e. '\a'), it worked fie in codeblocks, but it isn't working at all in vs code even with the same code as what I wrote in codeblocks. I've seen c tutorials in c, so I do know that vs code do support this escape sequence, but idk why it isn't working in my case.

What I have tried:

A sample of code which I tried on both codeblocks and vs code is:

<pre>#include<stdio.h>

int main()
{
    printf("\a");
    _sleep(1000);
    printf("\a");
    return 0;
}


(btw, here I wrote \a 2 times, but it wasn't working even when I wrote it only once).
Posted
Updated 12-Sep-22 11:27am
Comments
jeron1 12-Sep-22 15:50pm    
Try adding a second backslash character, an escape character,

"\\a"

https://en.cppreference.com/w/cpp/language/escape


Oi, misread the OP.

Works fine for me, though if you're expecting a beep out of the internal PC speaker, that's not where the sound comes from. Today, a "beep" would be whatever sound is configured in the Windows Sound control panel and come out of the sound card/motherboard audio and any speakers attached to that.

To see if you have a beep sound configured, open Control Panel -> Sound -> Sounds tab -> Default Beep. If there is a speaker next to "Default Beep", there is a sound configured. Click "Default Beep" and the "Test" button to hear that sound. That's the sound you'll get from your code when the "\a" character is used.
 
Share this answer
 
Comments
Everything Select 12-Sep-22 17:45pm    
If this is what the problem is, then shouldn't it also not work in codeblocks as well?
Dave Kreskowiak 12-Sep-22 19:25pm    
First, codeblocks is an IDE. It does not run your code. It compiles your code into an executable and you run that. What code it generates and the libraries it's using to run your code I have no idea about.

I'm telling you what to check with the code you're writing now.
printf() may not flush the output buffer until a newline ('\n') is seen, or the output buffer is full. Try adding fflush(stdout); after each printf(), to force the buffer to be flushed.
 
Share this answer
 
Comments
Everything Select 12-Sep-22 17:49pm    
It is still not working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900