代码功能
在电脑上运行一下,电脑将显示
“请注意,你的电脑将在1分钟内关机,如果输入:我是猪,就取消关机“
谁会承认自己是猪🐖呢?Ta必然会反抗,打入”你才是猪“等字样
这时候倒计时将不会结束,只有打出我是猪,电脑才会取消关机。
代码修改
如果是表白,可以将”我是猪“改成你想设置的字样
例如
printf("请注意,你的电脑将在1分钟内关机,如果输入:我是猪,就取消关机\n");
改成
printf("请注意,你的电脑将在1分钟内关机,如果输入:我喜欢XXX,就取消关机\n");
关机的倒计时也可以修改
system("shutdown -s -t 60");
将60改成你想要的数字
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char input[20] = { 0 };
system("shutdown -s -t 60");//system()执行系统命令,60秒后关机
again:
printf("请注意,你的电脑将在1分钟内关机,如果输入:我是猪,就取消关机\n");
scanf("%s", input);
if (strcmp(input,"我是猪")==0)//strcmp函数,比较两个字符串是否相同
{
system("shutdown -a");
}
else
{
goto again;//goto 到again,重新执行
}
return 0;
}
大家快去试试吧!