设为首页 加入收藏

TOP

C语言实现定时关机的代码教程
2018-05-26 14:14:00 】 浏览:216
Tags:语言 实现 定时 关机 代码 教程

C语言实现定时关机的代码教程

#include<stdio.h>  
#include<string.h>  
#include<stdlib.h>  

int main()
{
    char cmd[20] = "shutdown -s -t ";
    char times[10] = "0";
    int min = 0;
    int choose;

    system("title Timing Shutdown Program");  //设置cmd窗口标题  
    system("mode con cols=50 lines=35");  //窗口宽度高度   
    system("color f0");  //可以写成 red 调出颜色组  
    system("date /T");
    system("TIME /T");

    printf("\nWhat do you want me to do ...\n");
    printf("\n1.Timing Shutdown\t");
    printf("2.Shutdown\n");
    printf("3.Logout\t");
    printf("\t4.Shutdown Cancel\n");
    printf("0.Exit\n\n");
    printf("-> ");

    while (~scanf("%d", &choose))
    {
        switch (choose) {
        case 1:
            printf("Set a timer to count down...(minutes) \n");//输入分钟
            printf("-> ");
            scanf("%d", &min);
            min = min * 60;
            sprintf(times, "%d", min);
            system(strcat(cmd, times));
            printf("Hey,you can input 4 to cancel shutdown progress whenever you want...\n");
            break;
        case 2:
            system("shutdown -p");
            break;
        case 3:
            system("shutdown -l");
            break;
        case 4:
            system("shutdown -a");
            break;
        case 0:
            exit(0);
            break;
        default:
            printf("-> Please input right number!\n");
        }
    }
    return 0;
}
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇冒泡排序算法C语言代码测试总结 下一篇【C语言教程】C语言中的字符串解析

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目