关机程序
goto语句
#include<string.h>//两个字符串比较
#include<stdlib.h>//system
int main()
{
char input[20] = { 0 };
system("shutdown -s -t 60");
again:
printf("请注意,你的电脑在一分钟内关机,如果输入:我是猪,可取消关机\n");
scanf("%s", input);
//if (input == "我是猪");//两个字符串比较不能使用== 应该使用strcmp()string compare
if (strcmp(input, "我是猪") == 0)
{
system("shutdown -a");
printf("取消关机\n");
}
else
{
goto again;
}
return 0;
}
while语句
#include<string.h>//两个字符串比较
#include<stdlib.h>//system
int main()
{
char input[20] = { 0 };
system("shutdown -s -t 60");
while (1)
{
printf("请注意,你的电脑在一分钟内关机,如果输入:我是猪,可取消关机\n");
scanf("%s", input);
//if (input == "我是猪");//两个字符串比较不能使用== 应该使用strcmp()string compare
if (strcmp(input, "我是猪") == 0)
{
system("shutdown -a");
break;
}
}
return 0;
}
运行结果如下: