经常躺床上用猎豹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;
}