整理文件发现以前写的定时关机小程序(Windows下)
1-效果
2-程序
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
//界面
printf("-------自动关机小程序-------\n");
printf("您想在几分钟后关机?请输入正整数:");
//定义变量
unsigned long long second;
unsigned int minutes;
char charsecond[100] = {};
char arr[100] = {};
char cmd[20] = "shutdown -s -t ";
char input[20];
scanf("%d", &minutes); //读取分钟数
second = 60 * minutes; //计算秒数
// printf("%d\n", second);
itoa(second, charsecond, 10); //将数字转化为字符串
strcpy(arr, strcat(cmd, charsecond));
system(arr);//执行关机命令
// printf("%s%s", arr, "\n");
printf("系统将于%d分后关机,输入“stop”可取消关机\n", minutes);
while (1) {
scanf("%s", input);
if (0 == strcmp(input, "stop")) {
system("shutdown -a");
printf("关机操作已经被取消\n");
printf("5秒后程序自动关闭,倒计时:\n");
int i;
for (i = 5; i > 0; i--) {
printf("%d ", i);
sleep(1);
}
break;
} else {
printf("关机继续\n");
}
}
return 0;
}
标签:关机,arr,Windows,char,second,printf,定时,minutes From: https://www.cnblogs.com/FishSmallWorld/p/17087491.html