×

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

How to find square root in C Language

Before understanding the square root program in C language, one must know about the square root of a number. A square root is a mathematical term. The square root of a...

5 minutes read.

Difference between Array and List in C

C# Array vs List is where the abstraction and implementation of human computing meet.  Arrays are incredibly related to the hardware concept of contiguous and contiguous memory, where each part is...

3 minutes read.

Ferror() in c

Ferror():  In C, the ferror() function checks assuming there is a blunder in the given stream. The ferror() function is utilized to check for the document blunder on given stream. A return...

4 minutes read.

C Program for Extended Euclidean algorithms

The Euclidean method simply computes the GCD (greatest common divisor) of two numbers, p and q. (Let's assume) The GCD of two integers is the greatest number that divides them both....

3 minutes read.

pow() function in C

pow() function is one of the in-built functions present in math.h header file Power function is used to calculate the powers of the given number. The syntax of the power...

3 minutes read.

Array to function in C

Array to function in C We can create functions that receive an array as an argument. To pass an array into a function, we need to write the name of the...

4 minutes read.

Macros in C

In the C programming language, the macro is defined as a segment of the code replaced by the macro defined value at the beginning. ‘#define’ is the directive that defines...

3 minutes read.

C Language Environment Setup

To compile C program, we must have GCC compiler installed on our machine. In this C tutorial, all the examples are compiled and tested using GCC compiler. Although we can...

3 minutes read.

Types of Pointers in C

Pointers in C A pointer is a variable and this variable contains the address of another variable, i.e it’s a variable which has the address of another variable as its value....

4 minutes read.

clrscr in C

clrscr function in C clrscr stands for: clr = clear scr= screen When the clrscr() function is called in a program everything currently displayed in the console(output of previous programs, output of current program,...

3 minutes read.

Random Access - Lseek in C

Introduction lseek is a system call that is used to alter the location of the read/write pointer of a file descriptor. The lseek system call basically moves the current read/write location...

4 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.

Different ways to Declare the Variable as Constant in C

There are a wide range of ways of making the variable as steady Using const keyword: The const catchphrase permits a software engineer to inform the compiler that a specific variable should...

5 minutes read.

String in C

String is a collection of character or group of characters. In array, string of character is terminated by a null value “\0” and enclose between double quote. We can declare...

2 minutes read.

Difference between C and Java

C programming and Java programming are two of the earliest programming languages. C programming follows a procedural approach whereas Java programming follows an object-oriented approach. Java programming is a part...

3 minutes read.

C Program to Find Largest Number Using Dynamic Memory Allocation

This tutorial will teach us how to locate the highest number a user has ever input into a dynamically allocated memory. C Program: #include <stdio.h> #include <stdlib.h> int main ()  {   int no;   double *data_n;   printf...

1 minute read.

Diffie-Hellman Algorithm in C

Background: A method of public-key encryption known as elliptic curve cryptography (ECC) is based on the algebraic structure of elliptic curves over finite fields. To ensure equal security, ECC encryption requires fewer...

4 minutes read.

GCD program in C

C language : Dennis Ritchie developed the general-purpose computer language C at Bell Laboratories in 1972. Despite being an ancient language, it is extremely popular. It is among the most widely used...

4 minutes read.

Find the Largest Three Distinct Elements in an Array using C/C++

In this tutorial, we will demonstrate how to use a C/C++ programme to locate the highest three different elements in an array. C/C++ Program to Find the Largest Three Different Elements...

3 minutes read.

Array Of Structures in C

The C programming language allows us to store multiple elements of the same type in arrays. We can use strings to store multiple elements of a character data type. Still,...

4 minutes read.