一、goto语句
#include<stdio.h>
int main()
{
flag:
printf("hello world\n");
printf("hello world\n");
goto flag;
return 0;\\goto语句尽量不要使用
}
shutdown -s -t 60//设置六十秒后关机
shutdown -a//取消关机
c语言提供了一个函数:system()-执行系统命令
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char input[20] = { 0 };
system("shutdown -s -t 300");
again:
printf("请注意,你的电脑将在1分钟内关机,输入:我是猪,取消关机\n");
scanf("%s", input);
if (strcmp(input,"我是猪")==0)//两个字符串比较不能用等号
{
printf("不关机了\n");
system("shutdown -a");
}
else
{
goto again;
}
return 0;
}
goto语句只能在一个函数范围内跳转,不能跨函数
在多层函数嵌套使用时可以使用goto函数跳出循环语句