我们先要知道关机和暂停关机的命令;
关机 shutdown -s -t 60 (在60秒内关机);
暂停关机 shutdown -a;
这样我们就可以简单写一个关机代码;
在使用system时要包含头文件#include <stdlib.h>;
#include<stdio.h>
#include<stdlib.h>
int main()
{
system("shutdown -s -t 60");
return 0;
}
运行此代码就会关机;
这样我们来实现一个恶搞;
#include <stdio.h>
#include <stdlib.h>
int main()
{
char input[10] = { 0 };
system("shutdown -s -t 60");
while (1)
{
printf("电脑将在1分钟内关机,如果输入:我是猪,就取消关机!\n请输入:>");
scanf("%s", input);
if (0 == strcmp(input, "我是猪"))
{
system("shutdown -a");
break;
}
}
return 0;
}