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;
}

猜你喜欢

转载自blog.csdn.net/tron_future/article/details/80457667
今日推荐