×

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

Related Topics

Reverse a Stack using Recursion in C

In this tutorial we will learn how recursion will be used in this case to reverse a stack. For loops, while loops, do-while loops, and similar constructions are not permitted....

5 minutes read.

Malloc function in C

When the user or programmer does not know how much memory space is needed in the application, it a needs dynamic memory allocation during runtime. Dynamic memory allocation helps us to...

4 minutes read.

fork() in C

Introduction To create a new function in the system, there is a need for a system call, i.e. fork system call. It is also known as the child process. These child...

2 minutes read.

Conditional Operator in C

In C programming language, the conditional operator (also known as the ternary operator) is a shorthand way of writing an if-else statement. The syntax of conditional operator in C is...

3 minutes read.

Prime Number code in C

Prime Number Programs in C language In this tutorial, we will learn how to check whether the given number is a prime number or not, and how to print all the...

4 minutes read.

Header files in C

Header files in C In the C programming language, header files are present, which have an extension of ‘.h’, and it consists of macro definitions, declarations, and so on that are...

4 minutes read.

Pi() Function in C

Pi: Mathematic constants are not defined in the c or c++ programming languages. To use the Mathematical constants firstly, we have to define the _USE_MATH_DEFINES and then declare the cmath and...

3 minutes read.

Armstrong Number in C

The Armstrong number is defined as the sum of each of its digits to the power of the number base for the each given number with any given number base....

3 minutes read.

Comments in C

Comments are used to comment on the line of code in the program. Comments are a way of inserting remarks and reminders into code without affecting its behavior. The compiler...

1 minute read.

Flow Chart of For loop in C

This is a flowchart that represents the process of executing the for loop in the C programming language. Generally, as we know there are three main components of for loop:1. The...

3 minutes read.

If Statement in C

Decision Control Statements We frequently desire one set of instructions to be carried out in one circumstance while another set of instructions to be carried out in a completely different circumstance....

3 minutes read.

Write() function in c

As the name suggests the write () function is used to write the file descriptor. In other words it is used to write any file name without specifying file name,...

3 minutes read.

SJF Scheduling Program in C

The SJF (shortest job first) or the shortest job next is the programming scheduling in the C. It is one of the CPU scheduling programming. The SJF is defined as...

4 minutes read.

What is 2s Complement in C?

The complement of 2s in C is generated from the 1s in C. As we know, the 1s complement of a binary number is generated by converting bit 1 to...

4 minutes read.

Purpose of a Function Prototype in C

A function prototype in C is a declaration of a function that specifies the function's name, return type and parameters. It has the following syntax: return_type function_name(parameter_list); For example, the prototype for...

4 minutes read.

Java Array vs ArrayList

As we all know, arrays are linear data structures that allow you to add elements to them continuously in memory address space, whereas ArrayList is a Collection framework class. Despite...

4 minutes read.

What are linker and loader in C

Linker and loader are utility programs that have a significant role in executing a program. Linker: A linker is a program that joins the object files produced by the assembler/ compiler...

3 minutes read.

Break, continue and goto statement in C

Break statement Break statement is used to break the process of a loop (while, do while and for) and switch case. Syntax: break; Example 1 while(test Expression) { // codes if(condition for break){ break; } // codes } Example 2 For(int it, condition,...

1 minute read.

Ceil function in C

Introduction In the C Programming Language, the ceil function is a library function which is used to obtain the ceil value, i.e., it returns the smallest integer that is greater than...

4 minutes read.

Flow Chart of Do while loop in C

This is a flowchart that represents the process of executing the Do while loop in the C programming language Generally, as we know there are three main components of Do While...

3 minutes read.