调用System命令,用C程序实现自动关机。
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char input[20] = { 0 };
system("shutdown -s -t 1800");
again:
printf("您的电脑将在半小时后关机,请输入 开心 取消关机噢!\n");
scanf("%s", &input);
if (strcmp("开心", input) == 0)
{
system("shutdown -a");
printf("\n关机取消!\n");
}
else
{
goto again;
}
return 0;
}
Ps:
#include <stdlib.h> //调用系统命令,所需要的库函数
#include <string.h> //输入字符串判断对比,所需要的库函数
运行命令时保存好此时电脑上所正在编辑的文档,以及其他保存操作。