#define _CRT_SECURE_NO_WARNINGS //专门用于vs编辑器的scanf函数的
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
int main()
{
char input[20] = { 0 };
unsigned int time1 = 0;
time1 = (unsigned int)time(NULL);
system("shutdown -s -t 60");//system库函数,用于执行系统命令
while (1)
{
unsigned int time2 = (unsigned int)time(NULL);
printf("计算机将在 %u 秒后关机,如果不想计算机关机,就输入:>我是猪\n", 60 - (time2 - time1));
printf("%d",60-(time2 - time1));
scanf("%s", input);//VS中如果不用第一行代码可以用函数:scanf_s
if (strcmp(input, "我是猪") == 0)//strcmp是字符串比较函数
{
system("shutdown -a");
printf("恭喜你猪,关机程序结束\n");
break;
}
printf("输入错误,拜拜\n");
}
return 0;
}
可以试试