shutdown指令
-s 关机
-t 设置关机时间 ...秒
eg : 电脑搜cmd,可输入指令shutdown -s -t 60 //倒计时60秒关机
shutdown -a //可取消关机
<stdlib>头文件 system -- 库函数,可执行命令
goto语句:
#include<stdlib.h> //system函数
#include<string.h> //字符串strcmp,返回 0 则相等
int main()
{
char input[20] = {0};
system("shutdown -s -t 60");
again:
printf("请注意,你的电脑将在1分钟内关机,请输入:我是猪。取消关机\n");
scanf("%s",input); //输入的信息存在input数组中
//判断input中是不是“我是猪”
//两个字符串比较相等,不能使用==,应该用 strcmp
if(strcmp("我是猪",input)==0)
{
system("shutdown -a");
}
else
{
goto again;
}
return 0;
}
while循环:
#include<stdlib.h> //system函数
#include<string.h> //字符串strcmp
int main()
{
char input[20] = {0};
system("shutdown -s -t 60");
while(1)
{
printf("请注意,你的电脑将在1分钟内关机,请输入:我是猪。取消关机\n");
scanf("%s",input); //输入的信息存在input数组中
//判断input中是不是“我是猪”
//两个字符串比较相等,不能使用==,应该用 strcmp
if(strcmp("我是猪",input)==0)
{
system("shutdown -a");
break;
}
}
return 0;
}
如果想整蛊你的朋友:
debug版本改成release版本,找到路径release文件(.exe)发给你的朋友哈哈哈