温馨提示:
各位在编码的同时也不要忘了锻炼身体,身体才是我们持久卷下去的资本 
?
目录
??一、cmd指令实现关机
?二、goto语句版本
??三、循环语句版本
??四、运行效果

?
??一、cmd指令实现关机


?
?二、goto语句版本
#include<stdio.h>
#include<stdlib.h>
int main()
{
//关机
//C语言提供了一个函数:system() - 执行系统命令的
char input[20] = { 0 };
system("shutdown -s -t 60");
again:
printf("请注意!你的电脑将在1分钟内关机,如果输入:我是猪,就取消关机\n");
scanf("%s", input);
if (strcmp(input, "我是猪") == 0)//两个字符串比较要用strcmp() string compare
{
system("shutdown -a");
}
else
{
goto again;
}
return 0;
}
?
??三、循环语句版本
#include<stdio.h>
#include<stdlib.h>
int main()
{
//关机
//C语言提供了一个函数:system() - 执行系统命令的
char input[20] = { 0 };
system("shutdown -s -t 60");
while (1)
{
printf("请注意!你的电脑将在1分钟内关机,如果输入:我是猪,就取消关机\n");
scanf("%s", input);
if (strcmp(input, "我是猪") == 0)//两个字符串比较要用strcmp() string compare
{
system("shutdown -a");
break;
}
}
return 0;
}
?
??四、运行效果


?
?
|