How to Create an Alert in C

If you want your alert to be portable and work on every computer, you can use the escape code "\a"., Use this example code., On Windows operating systems, you can use the Beep(int frequency, int ms)., Include the windows library., When you need a...

17 Steps 1 min read Advanced

Step-by-Step Guide

  1. Step 1: If you want your alert to be portable and work on every computer

    \a is defined as an audible alert, usually a beep.

    However, on some Unix operating systems it might produce a screen flash instead of a sound.
  2. Step 2: you can use the escape code "\a".

    printf("\a")
  3. Step 3: Use this example code.

    It makes a beep of a specified duration and frequency.On the Windows7 operating system, this function sends the beep to the sound card.

    This works only if the computer has speakers or headphones.

    On previous Windows versions, it sends the beep to the motherboard.

    This works on most computers and no external devices are required. , Add the following code at the beginning of your program: #include <windows.h>

    , 500 is close to the beep you get with \a. , 500 is a half of a second., return 0; } , return 0; }
  4. Step 4: On Windows operating systems

  5. Step 5: you can use the Beep(int frequency

  6. Step 6: int ms).

  7. Step 7: Include the windows library.

  8. Step 8: When you need a beep

  9. Step 9: use the following code: Beep(500

  10. Step 10: Change the first number with the frequency of the beep you want.

  11. Step 11: Change the second number with the duration of the beep in milliseconds.

  12. Step 12: Try a program that uses \a to make a beep when a key is pressed

  13. Step 13: uses ESC to exit: #include <stdio.h> #include <conio.h> int main() { while(getch() != 27) // Loop until ESC is pressed (27 = ESC) printf("\a"); // Beep.

  14. Step 14: Try a program that makes a beep of a given frequency and duration: #include <stdio.h> #include <windows.h> int main() { int freq

  15. Step 15: dur; // Declare the variables printf("Enter the frequency (HZ) and duration (ms): "); scanf("%i %i"

  16. Step 16: &dur); Beep(freq

  17. Step 17: dur); // Beep.

Detailed Guide

\a is defined as an audible alert, usually a beep.

However, on some Unix operating systems it might produce a screen flash instead of a sound.

printf("\a")

It makes a beep of a specified duration and frequency.On the Windows7 operating system, this function sends the beep to the sound card.

This works only if the computer has speakers or headphones.

On previous Windows versions, it sends the beep to the motherboard.

This works on most computers and no external devices are required. , Add the following code at the beginning of your program: #include <windows.h>

, 500 is close to the beep you get with \a. , 500 is a half of a second., return 0; } , return 0; }

About the Author

R

Richard Gibson

Writer and educator with a focus on practical home improvement knowledge.

159 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: