你的电脑将会在一分钟内关机,只要输入——我是猪,就取消关机

方法:(运行若出现警告:返回值被忽略,可以在开头添加#define _CRT_SECURE_NO_WARNINGS)

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h> //system头文件
#include<string.h> // strcmp头文件
int main()
{
char input[20] = { 0 }; //存储数据
//system是专门用来执行系统命令的
system("shutdown -s -t 60"); //60s关机
again:
printf("请注意!!你的电脑将会在一分钟内关机,只要输入“我是猪”,就取消关机\n");
scanf("%s", input); //%s——输入字符串
if (strcmp(input, "我是猪") == 0) //strcpm = string compare 判断input中是否放入“我是猪”
{
system("shutdown -a"); //取消关机
}
else
{
goto again; //跳转
}
return 0;
}