dos.h header in C with examples - GeeksforGeeks

20 Jul, 2021
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:
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 Codeint main(){    printf("Takes 10 sec and exit.\n");     // Delay the program execution    // for 1 second    delay(10000);     return 0;}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 Codeint main(){    printf("Wait 2 sec and exit.\n");     // Delay the program execution    // for by 2 seconds    sleep(2);     return 0;}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 Codeint 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;}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 Codeint 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(): 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 Codeint 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;}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 Codeint 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;}
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 Codeint main(){    printf("Takes 10 sec and exit.\n");     // Delay the program execution    // for 1 second    delay(10000);     return 0;}
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 Codeint main(){    printf("Takes 10 sec and exit.\n");     // Delay the program execution    // for 1 second    delay(10000);     return 0;}
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 Codeint main(){    printf("Wait 2 sec and exit.\n");     // Delay the program execution    // for by 2 seconds    sleep(2);     return 0;}
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 Codeint main(){    printf("Wait 2 sec and exit.\n");     // Delay the program execution    // for by 2 seconds    sleep(2);     return 0;}
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 Codeint 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;}
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 Codeint 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;}
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 Codeint 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;}
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 Codeint 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(): 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 Codeint 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;}
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 Codeint 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;}
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 Codeint 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;}
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 Codeint 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;}
anikakapoor
C Language
C Programs
Computer Subject
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
TCP Server-Client implementation in C
Exception Handling in C++
Multithreading in C
'this' pointer in C++
Arrow operator -> in C/C++ with Examples
Strings in C
Arrow operator -> in C/C++ with Examples
C Program to read contents of Whole File
Header files in C/C++ and its uses
Basics of File Handling in C