解析: 运行此程序,必须输入正确才会取消关机,如果直接关闭程序或者输入错误,电脑到了一分钟会直接关机,必须输入正确的指令才会取消关机。
#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include<stdlib.h> #include<string.h> int main() {char input[20] = { 0 };//shutdown -s -t 60 关机命令60秒system("shutdown -s -t 60"); /*system执行系统命令的*/ again:printf("请注意!!!电脑将在1分钟之内关机,如果输入:取消关机 ,则电脑才会取消关机。n请输入>:");scanf("%s", input);if (strcmp(input,"取消关机")==0) /*strcmp() 比较2个字符串是否相等*/{system("shutdown -a"); //取消关机printf("已取消关机!n");}else{goto again;}return 0; }
#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include<stdlib.h> #include<string.h> int main() {char input[20] = { 0 };system("shutdown -s -t 60");while (1){printf("请注意!!!电脑将在1分钟之内关机,如果输入:取消关机 ,则电脑将会取消关机。n");printf("请输入>:");scanf("%s", input);if (strcmp(input, "取消关机") == 0) {system("shutdown -a");printf("已取消关机!n");break;}}return 0; }
本文发布于:2024-02-01 01:51:12,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170672347432994.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |