
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Amazing stuff with system() in C / C++?
Here we will see some amazing results by using the system() function in C or C++. The system function is present in Windows, Linux and MAC operating systems. This function is used to execute the system commands that can be written in Command line.
Here we will see two usages if system function in C or C++. The first one is getting the IP configuration details using C++ program.
Example
#include <iostream> #include <cstdlib> using namespace std; int main() { system("C:\Windows\System32\ipconfig"); }
Output
Windows IP Configuration Ethernet adapter Local Area Connection: Connection-specific DNS Suffix . : domain.name Link-local IPv6 Address . . . . . : fe80::302b:9dff:1cfb:ff01%10 IPv4 Address. . . . . . . . . . . : 192.168.2.6 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : fe80::217:7cff:fe3d:31c8%10 192.168.2.1 Ethernet adapter VirtualBox Host-Only Network: Connection-specific DNS Suffix . : Link-local IPv6 Address . . . . . : fe80::5c79:a124:f5b9:e0b7%13 Autoconfiguration IPv4 Address. . : 169.254.224.183 Subnet Mask . . . . . . . . . . . : 255.255.0.0 Default Gateway . . . . . . . . . : Ethernet adapter VirtualBox Host-Only Network #2: Connection-specific DNS Suffix . : Link-local IPv6 Address . . . . . : fe80::7c54:289:9257:dd7a%16 IPv4 Address. . . . . . . . . . . : 192.168.243.2 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : Tunnel adapter Teredo Tunneling Pseudo-Interface: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . : Tunnel adapter isatap.{E12FA520-1578-4264-A565-A1270D18177A}: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . : Tunnel adapter isatap.{A01195C5-0A34-4E50-89CB-4C391165B7C3}: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . : Tunnel adapter isatap.domain.name: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . : domain.name
The second one is more interesting. Using this we can turn off our computer. We will just write the shutdown program path inside the system function.
Example
#include <iostream> #include <cstdlib> using namespace std; int main() { system("C:\WINDOWS\System32\shutdown /s"); }
Output
One box will appear. It will tail the system is shutting down, then it will be shut down.
- Related Articles
- Set less important stuff with grey outlined Bootstrap 4 Button
- Amazing hacks of Python
- How can we stuff a string with another one using MySQL functions?
- Amazing images that capture you
- Power sleep do exciting stuff while sleeping
- Add a blue background color to an element to set key stuff with Bootstrap
- 10 Amazing Facts About Your Breasts
- Google docs features help to get stuff done
- 15 Amazing Facts about Left-Handed People
- 10 Amazing Facts About Your Blood Vessels
- System() Function in C/C++
- What are some amazing facts related to Facebook?
- What are some amazing projects built using Python?
- Essential – An Amazing Phone From the Creator of Android
- Raspberry pi hacks 8 of the most amazing ones

Advertisements