如何用c语言编辑定时关机程序有说明的,C语言编写的定时关机程序

经常躺床上用猎豹WiFi,又不想起来关机,就写了个定时关机的程序,C语言,源码1KB,编译后程序52K

#include

#include

#include

#include

main()

{

int shutHour,shutMinutes; // 关机的时间

struct tm *nowTime; // 现在时间

time_t t; // time类型,t中保存的是1970年1月1日到现在的秒数

long seconds; // 关机时间与现在时间的时间差

char secondString[10];

char cmd[30]="shutdown -s -t ";// 关机命令的字符串

// 此段获取当前时间

t = time(NULL);

nowTime = localtime(&t);

// 此段输入关机时间,并判断输入正误

printf("Input Time(**.**) you want to shutdown the computer:\n");

do{

while(scanf("%d.%d",&shutHour,&shutMinutes) != 2) continue;

}while(shutHour*3600+shutMinutes*60 < nowTime->tm_hour * 3600 + nowTime->tm_min * 60);

// 此段计算关机时间到现在时间的时间差

seconds = shutHour*3600+shutMinutes*60 - (nowTime->tm_hour * 3600 + nowTime->tm_min * 60);

// 此段生成关机的字符串命令

itoa(seconds,secondString,10);

strcat(cmd,secondString);

// cmd即为关机的命令shutdown -s -t seconds

system(cmd);

// 这是编译好的程序http://doc.xuehai.net/s/1c06b9tu

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值