在讲解关机程序前,必须得先知道一个库函数system("shutdown -s -t 60")和system("shutdown -a),其中“shutdown -s”表示关机,“shutdown -a”表示取消关机,“-t 60”表示延迟60秒;而要使用该库函数就得引头文件#include<stdlib.h>。


下面是实现关机程序代码:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char input[20] = { 0 };
system("shutdown -s -t 60");
do
{
printf("你的电脑将在一分钟后关机,如果输入:我是猪。就取消关机!\n请输入:");
scanf("%s", input);
if (strcmp(input, "我是猪") == 0)
{
system("shutdown -a");
break;
}
printf("输入错误!!\n");
} while (1);
return 0;
}

原文链接:https://blog.csdn.net/m0_66769266/article/details/124237897