欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-01-24 17:51:20
c语言实现定时关机的代码教程 #include #include #include...

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