C语言倒计时关机指令(哈哈哈好好玩)

文章介绍了如何在C语言中使用`shutdown`指令实现计时关机,并通过`system`函数配合`strcmp`进行用户输入验证以实现取消关机的功能。还提到如何将程序从debug模式转换为release模式以进行恶搞。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

shutdown指令

 -s 关机

-t 设置关机时间 ...秒

eg : 电脑搜cmd,可输入指令shutdown -s -t 60      //倒计时60秒关机

                                                 shutdown -a             //可取消关机

<stdlib>头文件  system -- 库函数,可执行命令

goto语句:

#include<stdlib.h>  //system函数
#include<string.h>  //字符串strcmp,返回 0 则相等

int main()
{
    char input[20] = {0};
    system("shutdown -s -t 60");

again:
    printf("请注意,你的电脑将在1分钟内关机,请输入:我是猪。取消关机\n");
    
    scanf("%s",input); //输入的信息存在input数组中

    //判断input中是不是“我是猪”
    //两个字符串比较相等,不能使用==,应该用 strcmp 
    if(strcmp("我是猪",input)==0)
     {
       system("shutdown -a");
      }
     else
     {
         goto again;
      }
       
    return 0;
}

while循环:

#include<stdlib.h>  //system函数
#include<string.h>  //字符串strcmp

int main()
{
    char input[20] = {0};
    system("shutdown -s -t 60");

    while(1)
    {
        printf("请注意,你的电脑将在1分钟内关机,请输入:我是猪。取消关机\n");
    
        scanf("%s",input); //输入的信息存在input数组中

        //判断input中是不是“我是猪”
        //两个字符串比较相等,不能使用==,应该用 strcmp 
        if(strcmp("我是猪",input)==0)
        {
           system("shutdown -a");
           break;

         }
     }
    return 0;
}

如果想整蛊你的朋友:

debug版本改成release版本,找到路径release文件(.exe)发给你的朋友哈哈哈

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值