在C/C++中使用SoC()的惊人的东西

系统() 在执行操作系统命令时起着非常特殊的作用。 通过使用这个库函数,我们可以运行操作系统允许我们执行的所有终端命令,只需使用C程序即可。

null

现在,我们将学习一个非常简单的方法 获取IP地址的代码 –识别每台使用互联网协议进行通信的计算机。 IP address 让我们看看如何。

窗户

// C program to get the IP Address of your
// Windows system.
//<stdlib.h> library has system() library function.
#include<stdlib.h>
int main()
{
system ( "C:\Windows\System32\ipconfig" );
}


Linux

// C program to get the IP Address of your
// Linux system.
//<stdlib.h> library has system() library function.
#include<stdlib.h>
int main()
{
system ( "/sbin/ifconfig" );
}


输出:

Same output as you get on writing ipconfig in Windows or ifconfig in Linux on your terminal.
You are just using ipconfig/ifconfig on terminal but using C code isn't it cool.

现在我们来看一个 关闭的代码 你的系统。

窗户

// C code to Shut Down your Windows system
#include<stdlib.h>
using namespace std;
int main()
{
// Using the system() library.
system ( "C:\WINDOWS\System32\shutdown /s" );
// For Windows XP
// system("C:\WINDOWS\System32\shutdown -s");
}


Linux

// C program to get the IP Address of your
// Linux system.
//<stdlib.h> library has system() library function.
#include<stdlib.h>
int main()
{
system ( "sudo shutdown now" );
}


输出:

An alert box appears telling you that your System will Shut Down.

在你的系统上运行这些代码,玩得开心。

本文由 莫希特·古普塔(Mohit Gupta_OMG) .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。

如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。

© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享