Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Stop computer beeping when printing the number 7

I’m printing a bunch of ascii chars to the console as a representation of binary numbers however whenever it prints out the number 7 to the console then windows makes a beeping noise.
Looking online I can see some people talking about ascii 7 making a noise but I cant seem to find where to disable it in the code.

for (size_t i = 0; i < 1160; i++)
{
    std::cout << "\n" << (char)decimalarray[i];
}

this occurs when the value in the UIN8 array is 7 and I try printing the value as a char.
printing (int)decimalarray[1157] outputs the number 7
printing (char)decimalarray[1157] outputs nothing but makes beeping noise

edit: it would probably be ideal if there was a way to only write printable characters. not easy to hardcode in the values as the program uses every ascii character there is in normal execution.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Can anyone help? thanks

>Solution :

Code 7 is bell. It is meant to do that.

To disable it, you have 2 choices.

  • Change the configuration of the terminal or OS (tell it to be silent).
  • Add a conditional to the code, to skip this character.

To do the conditional: use isprint

e.g.

#include <ctype.h>
#include <iostream>

int main(){
    int c =7;
    
    if (isprint(c))
        std::cout <<'\n' << static_cast<char>(c);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading