The Wayback Machine - https://web.archive.org/web/20240922205202/https://www.geeksforgeeks.org/dos-h-header-in-c-with-examples/
Open In App

dos.h header in C with examples

Last Updated : 20 Jul, 2021
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

dos.h is a header file of C Language. This library has functions that are used for handling interrupts, producing sound, date and time functions, etc. It is Borland specific and works in compilers like Turbo C Compiler.
Below are the functions supported by this library:

  1. delay(): The delay() function in C is used to stop the execution of the program for some period of time.
    Syntax:

    delay(unsigned int)
    

    Parameters: It accepts a time in milliseconds to stop the execution of the program to that period of time.

    Below is the program to illustrate delay():




    // 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;
    }

    
    

  2. sleep(): The sleep() function in C is used to delay the execution of the program for some period of time.
    Syntax:

    sleep(unsigned seconds)
    

    Parameters: It accepts a time in seconds to delay the execution of the program to that period of time.

    Below is the program to illustrate sleep():




    // 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;
    }

    
    

  3. getdate(): The getdate() function in C is used to get the current Date of the system.

    Syntax:

    getdate(struct date d)
    

    Parameters: It accepts a structure date which is defined in dos.h library itself. To print the date it uses function da_day(), da_mon() and da_year().

    Below is the program to illustrate getdate():




    // C program to implement getdate()
    #include <dos.h>
    #include <stdio.h>
    #include <stdlib.h>
     
    // Driver Code
    int main()
    {
        // Structure of date
        struct date a;
     
        // Function call to get the date
        // of the system
        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;
    }

    
    

  4. gettime(): The gettime() function in C is used to get the Time shown by the System.

    Syntax:

    gettime(struct time t)
    

    Parameters: It accepts a structure time which is defined in dos.h library itself. To print the date it uses function ti_hour(), ti_min() and ti_sec().

    Below is the program to illustrate gettime():




    // 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;
    }

    
    

  5. sound(): The sound() function in C is used to play different sound on different frequency on our system.

    Syntax:

    sound(int frequency)
    

    Parameters: It accepts a frequency and play the sound of that frequency in our system.

    Below is the program to illustrate sound():




    // 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;
    }

    
    

  6. nosound(): The nosound() function in C is used to stop the sound played by souns() function.

    Syntax:

    nosound()
    

    Parameters: It doesn’t accepts any parameters.

    Below is the program to illustrate nosound():




    // C program to implement nosound()
    #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;
    }

    
    



Similar Reads

MS-DOS Operating System
IBM was looking for an operating system for their new line of personal computers. Bill Gates's mother Marry M Gates served on the national board of United Way alongside the CEO of IBM. IBM got in touch with Bill Gates through his mother when he convinced IBM that his company Microsoft could deliver the new software for IBM's personal computer. Bill
7 min read
&lt;complex.h&gt; header file in C with Examples
Most of the C Programs deals with complex number operations and manipulations by using complex.h header file. This header file was added in C99 Standard. C++ standard library has a header, which implements complex numbers as a template class, complex&lt;T&gt;, which is different from &lt;complex.h&gt; in C. Macros associated with &lt;complex.h&gt;
5 min read
time.h header file in C with Examples
The time.h header file contains definitions of functions to get and manipulate date and time information. It describes three time-related data types. clock_t: clock_t represents the date as an integer which is a part of the calendar time. time_t: time_t represents the clock time as an integer which is a part of the calendar time. struct tm: struct
4 min read
Difference between Header file and Library
Header Files: The files that tell the compiler how to call some functionality (without knowing how the functionality actually works) are called header files. They contain the function prototypes. They also contain Data types and constants used with the libraries. We use #include to use these header files in programs. These files end with .h extensi
3 min read
Cross Domain Referrer Header Leakage
Referrer Header is a request header used to obtain information about what is the previous URL or link from which the current website is reached. This information is used in many typical business use cases. The referrer header as the name implies is used to obtain information about the URL that refers to the current URL. For security reasons, Referr
3 min read
Options Field in IPv4 Header
All IP datagrams must have the standard 20-byte header, which contains key information such as the source and destination address of the datagram, fragmentation control parameters, length information, and more. In addition to these invariable fields, the creators of IPv4 included the ability to add options that provide additional flexibility in how
4 min read
Options Field in TCP Header
TCP users communicate with each other by sending packets. The packet contains data and other information about the source and destination and other TCP variables. These details are stored in the TCP header which is the top part of the packet. When a data packet is transmitted via different network devices the header is processed every time and then
5 min read
What’s difference between header files "stdio.h" and "stdlib.h" ?
These are two important header files used in C programming. While “&lt;stdio.h&gt;” is header file for Standard Input Output, “&lt;stdlib.h&gt;” is header file for Standard Library. One easy way to differentiate these two header files is that “&lt;stdio.h&gt;” contains declaration of printf() and scanf() while “&lt;stdlib.h&gt;” contains declaratio
2 min read
Comment in header file name?
What happens if there is a comment in header file name? Parsing of `#include' is slightly special because comments are not recognized within the ''. Thus, in `#include ' the `/*' does not start a comment and the directive specifies inclusion of a system header file named `x/*y'. Of course, a header file with such a name is unlikely to exist on Unix
1 min read
numeric header in C++ STL | Set 2 (adjacent_difference(), inner_product() and iota())
The numeric header is part of the numeric library in C++ STL. This library consists of basic mathematical functions and types, as well as optimized numeric arrays and support for random number generation. Some of the functions in the numeric header: iotaaccumulatereduceinner_productpartial_sum etc. See this article for more reference: accumulate()
4 min read
Print "Hello World" in C/C++ without using any header file
Write a C/C++ program that prints Hello World without including any header file. Conceptually it's seems impractical to write a C/C++ program that print Hello World without using a header file of "stdio.h". Since the declaration of printf() function contains in the "stdio.h" header file. But we can easily achieve this by taking the advantage of C p
2 min read
How to write your own header file in C?
As we all know that files with .h extension are called header files in C. These header files generally contain function declarations which we can be used in our main C program, like for e.g. there is need to include stdio.h in our C program to use function printf() in the program. So the question arises, is it possible to create your own header fil
4 min read
Logical Not ! operator in C with Examples
! is a type of Logical Operator and is read as "NOT" or "Logical NOT". This operator is used to perform "logical NOT" operation, i.e. the function similar to Inverter gate in digital electronics. Syntax: !Condition // returns true if the conditions is false // else returns false Below is an example to demonstrate ! operator: Example: // C program t
1 min read
iswprint() in C/C++ with Examples
The iswprint() is a built-in function in C/C++ which checks if the given wide character can be printed or not. It is defined within the cwctype header file of C++. By default, the following characters are printable: Digits (0 to 9)Uppercase letters (A to Z)Lowercase letters (a to z)Punctuation characters (!"#$%&amp;'()*+, -./:;?@[\]^_`{|}~)Space Sy
2 min read
iswgraph() in C/C++ with Examples
The iswgraph() is a built-in function in C/C++ which checks if the given wide character has a graphical representation or not. It is defined within the cwctype header file of C++. By default, the following characters are graphic: Digits (0 to 9)Uppercase letters (A to Z)Lowercase letters (a to z)Punctuation characters (!"#$%&amp;'()*+, -./:;?@[\]^_
2 min read
btowc() function in C/C++ with Examples
The btowc() is a built-in function in C/C++ which converts a character to its wide character equivalent. It is defined within the cwchar header file of C++. Syntax: wint_t btowc( int ch ); Parameter:The function accepts a single mandatory parameter ch which specifies the single byte character to convert to it's wide character. Return Value: The fun
2 min read
mbrtoc16() in C/C++ with Examples
The mbrtoc16() is a built-in function in C/C++ which converts a narrow multibyte character to a 16 bit character representation. It is defined within the uchar.h header file of C++. Syntax: ssize_t mbrtoc16( char16_t* pc16, const char* s, size_t n, mbstate_t* ps); Parameters: The function accepts four mandatory parameter which are described below:
3 min read
mbrtoc32() in C/C++ with Examples
The mbrtoc32() is a built-in function in C/C++ which converts a narrow multibyte character to a 32 bit character representation. It is defined within the uchar.h header file of C++. Syntax: size_t mbrtoc32( char32_t* pc32, const char* s, size_t n, mbstate_t* ps); Parameters: The function accepts four mandatory parameter which are described below: s
3 min read
wmemset() in C/C++ with Examples
The wmemset() function is a builtin function in C/C++ which copies a single wide character for a specified number of time to a wide character array. It is defined within the cwchar header file in C++. Syntax: wmemset(des, ch, count) Parameters: The function accepts three parameters which are described below. des: It specifies to the wide character
2 min read
wcsspn() function in C/C++ with Examples
The wcsspn() is a built-in function in C/C++ which returns the length of maximum initial segment of the wide string that consists of characters present in another wide string. It is defined within the cwchar header file of C++. Syntax: wcsspn(des, src) Parameters:The function accepts two mandatory parameters as described below. des: specifies to a
2 min read
cauchy_distribution a() in C++ with Examples
The cauchy_distribution::a() function is an inbuilt function in C++ STL which is used to returns the distribution parameter associated with Cauchy distribution. The class cauchy_distribution is present in header file random. Before going to the syntax of the function, brief introduction to Cauchy Distribution. Cauchy Distribution A random variable
2 min read
SDL library in C/C++ with examples
SDL is Simple DirectMedia Layer.It is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D.It can be used to make animations and video games. It basically provides a set of APIs to interact with various devices like graphics hardware, audio, keyb
4 min read
getdate() and setdate() function in C with Examples
setdate() Method: getdate() function is defined in dos.h header file. This function fills the date structure *dt with the system's current date. Syntax struct date dt; getdate(&amp;dt); Parameter: This function accepts a single parameter dt which is the object of structure date. Return Value: This method does not return anything. It just gets the s
2 min read
asctime() and asctime_s() functions in C with Examples
asctime() function The asctime() function returns the pointer to the string that contains the information stored in the structure of the struct tm type. This function is used to return the local time defined by the system in string format. This function is defined in &lt;time.h&gt; header file. Syntaxchar *asctime(const struct tm* tm_ptr);Parameter
3 min read
time.h localtime() function in C with Examples
The localtime() function is defined in the time.h header file. The localtime( ) function return the local time of the user i.e time present at the task bar in computer. Syntax: tm* localtime(const time_t* t_ptr); Parameter: This function accepts a parameter t_ptr which represents the pointer to time_t object. Return Value: This function returns a p
1 min read
Arrow operator -&gt; in C/C++ with Examples
An Arrow operator in C/C++ allows to access elements in Structures and Unions. It is used with a pointer variable pointing to a structure or union. The arrow operator is formed by using a minus sign, followed by the greater than symbol as shown below. Syntax: (pointer_name)-&gt;(variable_name) Operation: The -&gt; operator in C or C++ gives the val
4 min read
unsigned char in C with Examples
char is the most basic data type in C. It stores a single character and requires a single byte of memory in almost all compilers. Now character datatype can be divided into 2 types: signed char unsigned char unsigned char is a character datatype where the variable consumes all the 8 bits of the memory and there is no sign bit (which is there in sig
2 min read
ctype.h(&lt;cctype&gt;) library in C/C++ with Examples
As string.h header file contains inbuilt functions to handle Strings in C/C++, the ctype.h/&lt;cctype&gt; contains inbuilt functions to handle characters in C/C++ respectively. Characters are of two types: Printable Characters: The characters that are displayed on the terminal. Control Characters: The characters that are initiated to perform a spec
5 min read
C fopen() function with Examples
The fopen() method in C is a library function that is used to open a file to perform various operations which include reading, writing, etc. along with various modes. If the file exists then the fopen() function opens the particular file else a new file is created. SyntaxThe syntax of C fopen() is: FILE *fopen(const char *file_name, const char *mod
4 min read
&lt;cfloat&gt; float.h in C/C++ with Examples
This header file consists of platform-dependent and implementation specific floating point values. A floating point has four parts. Sign Its value can be either negative or non-negative. Base It is also known as radix of exponent representation which represents different numbers with single number i.e. 2 for binary, 10 for decimal, 16 for hexadecim
4 min read