新年快乐!昨天是除夕,算是休息了一天,今天学习了几道编程题还有goto语句,编程题一道是字符从两端移动向中间汇聚,一道是模拟密码三次机会的输入,猜数字游戏,求素数,打印闰年,这些编程题理解起来不困难,但是让我自己写出来还是有点难度的,其次就是goto语句了。
go to语句
goto语句可以没有,跳转只能在一个函数范围内跳转
一个关机程序
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
char input[10] = {0};
system("shutdown -s -t 60");
again:
printf("电脑将在1分钟内关机,如果输入:我是猪,就取消关机!\n请输入:>");
scanf("%s", input);
if(0 == strcmp(input, "我是猪"))//字符串比较函数
{
system("shutdown -a");
}
else
{
goto again;
}
return 0;
}
//shutdown - s 关机
//shutdown - a 取消关机
//system() - 执行系统命令
int main()
{
char input[10] = {0};
system("shutdown -s -t 60");
while(1)
{
printf("电脑将在1分钟内关机,如果输入:我是猪,就取消关机!\n请输入:>");
scanf("%s", input);
if(0 == strcmp(input, "我是猪"))
{
system("shutdown -a");
break;
}
}
return 0;
}
在项目文件夹中找到.exe文件就可以把文件发给朋友了,在桌面搜索服务,可以把.exe文件变成开机启动的服务类型。
goto用来跳出循环好用
for(...)
for(...)
{
for(...)
{
if(disaster)
goto error;
}
}
…
error:
if(disaster)