sound() and nosound() functions of dos.h in C

sound() and nosound() functions of dos.h in C: In this article, we are going to learn about the sound in programs and how we can use them with the help of our pre-defined functions of dos.h header file?
Submitted by Manu Jemini, on March 17, 2018

Our system can create various sounds on different frequencies. The example below demonstrates it nicely of how we can use the variable ‘a’ to generate different sound.

The delay() function has been used in this function to delay for the next sound. The Second thing is the nosound() function, which simply silent the system.

The sound() is very useful as it can create very nice music with the help of programming and our user can enjoy music during working in out the program.

These two functions are from file dos.h, which should be included in the program.

dos.h - sound() function Example in C



#include <stdio.h>
//to use 'sound()', 'delay()' functions
#include <dos.h>

int main()
{
	int k;
	//loop to increment the value of a till 100.
	for ( k = 1 ; a <= 100 ; a = k++ )
	{
		//calling the function for producing 
		//the sound of value a.
		sound(a);
		//delay the sound 10 miliseconds.
		delay(10);
	}
	// function to stop the system sound.
	nosound();
	return 0;
}

dos.h - nosound() function Example in C



#include <stdio.h>
//to use 'sound()', 'delay()' functions
#include <dos.h>

int main()
{
	//calling the function for producing 
	//the sound of frequency 400.
	sound(400);

	//function to delay the sound for 
	//half of second.
	delay(500);

	//calling the function to stop the 
	//system sound.
	nosound();

	return 0;
}



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.