当前位置:网站首页>goto语句实现关机小程序
goto语句实现关机小程序
2022-06-26 12:35:00 【小突突~】
C语言中提供了可以随意滥用的 goto语句和标记跳转的标号。从理论上 goto语句是没有必要的,实践中没有goto语句也可以很容易的写出代码。而goto语句无非就是直接跳到符号那里去,这个符号不固定,可以是其他的字母。下面是两张示范的图片。
goto语句也不能够跨函数跳转
goto语句最常见的用法就是终止程序在某些深度嵌套的结构的处理过程。
比如说,这样的一个三层for循环,你如果要跳出循环是不是就要用三个break。而使用goto语句就可以跳出这个三层循环。
接下来,我就要介绍一下一个用goto语句实现的关机小程序了。
首先我们要打开运行,输入cmd,打开命令行窗口,而shutdown就是电脑关机的系统命令。
而shutdown -s 表示设置关机,shutdown -t 表示设置时间关机,shutdown -60 表示60s后关机 shutdown -a 表示解除关机命令。


大家可以试一下,就知道你的电脑会不会关机了。
而在c语言中,我们要用到system这个系统函数来执行系统命令。那么一个关机程序肯定上来就启动了,这个时候我们要提醒别人啊,要不然那就真的关机了。然后就是把输入的字符串与“我是猪”进行比较,接下来就是把系统命令该写哪里写哪里。
#include <stdlib.h>
#include <string.h>
int main()
{
char input[20] = { 0 };
int i = 0;//输入次数
system("shutdown -s -t 60");
again:
printf("请注意,你的电脑将在一分钟后关机,如果输入:我是猪,则取消关机\n");
scanf("%s", input);
if (i > 10)
{
system("shutdown -s -t 0");
}
if (strcmp(input, "我是猪") == 0)
{
system("shutdown -a");
}
else
{
i++;
goto again;
}
return 0;
}
我的关机程序还规定了一个输入次数,如果你头铁没有输“我是猪”,那么10次过后你的电脑就真的关机了。博主真试了,真给我关机了。这就是一个简单的关机小程序。希望可以帮助到你,学编程嘛,不能总是那么枯燥。
边栏推荐
- Investment planning and forecast report on the future direction of China's smart agriculture during the 14th five year plan (2022)
- 小白懒人专用-win10-win11一键安装版
- Why is password salt called "salt"? [Close] - why is a password salt called a "salt"? [closed]
- Scala-day03- operators and loop control
- Nodejs framework express and KOA
- Lintcode 130 · stacking
- NoSQL mongodb - 04 mongodb database and web service combination case
- 由错误<note: candidate expects 1 argument, 0 provided>引发的思考
- Research on the current situation of China's modified engineering plastics market and demand forecast analysis report 2022-2028
- dried food! Yiwen will show you SD card, TF card and SIM card!
猜你喜欢

Scala-day03- operators and loop control

记一次phpcms9.6.3漏洞利用getshell到内网域控

Redis learning - 05 node JS client operation redis and pipeline pipeline

Several rare but useful JS techniques

Websocket and socket IO case practice

Php+laravel5.7 use Alibaba oss+ Alibaba media to process and upload image / video files

Vscode solves the problem of Chinese garbled code

Tiger DAO VC产品正式上线,Seektiger生态的有力补充

The laravel dingo API returns a custom error message

MS17_ 010 utilization summary
随机推荐
几行代码就能实现复杂的 Excel 导入导出,这个工具类真心强大!
Analysis report on dynamic research and investment planning suggestions of China's laser medical market in 2022
Realize microservice load balancing (ribbon)
Jsonarray and jsonobject of fastjson [easy to understand]
Introduction to the four major FPGA manufacturers abroad
NoSQL mongodb - 02 mongodb server installation, mongodb shell, basic concepts and visualization tools
sqlalchemy event listen Automatic generate CRUD excel
JMeter response time and TPS listener tutorial
International beauty industry giants bet on China
快手实时数仓保障体系研发实践
BigInt:处理大数字(任意长度的整数)
TP5 thinkphp5 extension package think Mongo operation mongodb time interval range query
Which is safer and better for great wisdom to open an account
[极客大挑战 2019]RCE ME 1
Investment planning and forecast report on the future direction of China's smart agriculture during the 14th five year plan (2022)
[redis series] redis learning 16. Redis Dictionary (map) and its core coding structure
nvm安装教程
机组实践实验8——使用CMStudio设计基于基本模型机微程序指令(1)
Ad - update the modified PCB package to the current PCB
Examples of how laravel uses with preload (eager to load) and nested query