当前位置:   article > 正文

如何使用简单c语言实现关机恶搞_暂停关机代码

暂停关机代码

我们先要知道关机和暂停关机的命令;

关机 shutdown -s -t 60 (在60秒内关机);

暂停关机 shutdown -a;

这样我们就可以简单写一个关机代码;

在使用system时要包含头文件#include <stdlib.h>;

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. int main()
  4. {
  5. system("shutdown -s -t 60");
  6. return 0;
  7. }

运行此代码就会关机;

这样我们来实现一个恶搞;

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main()
  4. {
  5. char input[10] = { 0 };
  6. system("shutdown -s -t 60");
  7. while (1)
  8. {
  9. printf("电脑将在1分钟内关机,如果输入:我是猪,就取消关机!\n请输入:>");
  10. scanf("%s", input);
  11. if (0 == strcmp(input, "我是猪"))
  12. {
  13. system("shutdown -a");
  14. break;
  15. }
  16. }
  17. return 0;
  18. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/456229
推荐阅读
相关标签
  

闽ICP备14008679号