ADVERTISEMENT
ADVERTISEMENT

Program to run DOS commands through a C program

In C programming language, to run DOS commands – system() function is used. The system() function is defined <process.h> header file.

Syntax:

int system(const char* command);

Program:

// Program to run dos commands through a C program

#include <stdio.h>
#include <process.h>

int main()
{
    int choice = 0;

    printf("\n***************************************\n");
    printf("1. Open Notepad...\n");
    printf("2. Get Ip Address...\n");
    printf("3. Shut down the computer...\n");

    printf("** Enter your choice :");
    scanf("%d", &choice);

    switch (choice) {
    case 1:
        system("notepad");
        break;
    case 2:
        system("ipconfig");
        system("pause");
        break;
    case 3:
        system("SHUTDOWN -S");
        system("pause");
        break;
    default:
        printf("\n Invalid choice !!!");
    }

    return 0;
}

Output:

***************************************
1. Open Notepad...
2. Get Ip Address...
3. Shut down the computer...
** Enter your choice :2

Windows IP Configuration


Ethernet adapter Local Area Connection 3:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::38d0:910:14e:498b%17
   IPv4 Address. . . . . . . . . . . : 192.168.1.111
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.1.1

Wireless LAN adapter Wireless Network Connection 2:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter Bluetooth Network Connection:
continue..   
    

C Miscellaneous Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.