Dos.h Header File in C Language
- Dos.h is a header file in C. Interrupt handling, sound generation, date and time functions, and other tasks can be performed using the functions in this library.
- This is exclusive to Borland and can be used with compilers such as the Turbo C compiler. The following functions are supported by this library:
Delay():
- In C, the delay() function is used to temporarily stop the execution of a program.
// C program to implement delay()
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
// Driver Code
int main()
{
printf("Takes 10 sec and exit.\n");
// Delay the program execution
// for 1 second
delay(10000);
return 0;
}
sleep():
- In C, the sleep() function is used to pause the execution of a program for a while parameters: Takes time in seconds to limit program execution to that time.
- The demo program sleep() looks like this:
// C program to implement sleep()
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
// Driver Code
int main()
{
printf("Wait 2 sec and exit.\n");
// Delay the program execution
// for by 2 seconds
sleep(2);
return 0;
}
getdate():
- To get the current system date, C uses the getdate() function Parameters: Accepts a date structure defined in the dos.h library itself.
- The da_day(), da_mon() and da_year() functions are used to print the date The getdate() demo program looks like this:
// C program to implement getdate()
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
// Driver Code
int main() {
// Structure of date
struct date a;
getdate(&a);
// Print the date, month and year
printf("The Date is: %d/%d/%d\n", a.da_day,
a.da_mon,
a.da_year);
return 0; }
gettime():
- The C function get time() is used to get the system time Parameters: Accepts the time structure defined in the dos.h library.
- The date is output with fnosound(): The souns() functions ti_hour(), ti_min() and ti_sec() can be stopped with the C function nosound().
- The get time() demo program looks like this:
// C program to implement gettime()
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
// Driver Code
int main()
{
// Structure of time
struct time t;
// Function call to get the time
// of the system
getdate(&t);
// Print the hour, minutes and second
printf("The time is: %d : %d : %d\n", x.ti_hour,
x.ti_min,
x.ti_sec);
return 0;
}
Sound():
- In our system, the sound() function in C is used to play different sounds with different frequencies.
- Options: It detects the frequency and plays the corresponding tone in our system.
- The sound demo() program looks like this:
// C program to implement sound()
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
// Driver Code
int main()
{
// Initialise frequency
int x = 200;
// Loop for playing sound of
// increasing frequency
for (; x < 1000; x++) {
// Function to play sound
sound(x);
delay(25);
}
// To stop the frequency
nosound();
return 0;
}
No sound():
- The nosound() function in C is used to stop the sound played by the sounds() function.
- Parameters: No parameters are accepted.
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
// Driver Code
int main()
{
// Initialise frequency
int x = 200;
// Function call to play sound
// with frequency 200htz
sound(x);
// Delay sound for 1 sec
delay(1000);
// To stop the sound
nosound();
return 0;
}
Using Standard Header Files
- #include: Input and output operations are performed using the scanf() and printf() functions. #include: Use cin and court to act as input and output streams. #include: Used for various string manipulation functions such as strlen(), strcmp(), strcpy(), size().
- #include<math.h>: Used to perform math operations such as pow(), sqrt(), log2(). #include: Used to access the set() and set precision() functions to limit the number of decimal places for variables.
- #include: Used by signal handler functions such as raise() and signal().
- #include: Standard argument functions such as va_start() and va_arg() are executed here. It is also used to fetch arguments from a variable-length argument list within a program and to indicate the start of a variable-length argument list
- #include: Errno, strerror, error, and other error handling functions rely on this. #include: Used to control what data is written to the file and what data is read from the file as output
- #include: Used to perform functionsrelated to date() and time() such as setdate() and getdate().
- They are also used to get the CPU time and change the system date re