在c语言编程中怎么用代码解除关机命令?

我写了一个程序,叫你回答问题,回答的不对就执行关机命令,系统就在指定时间内自动关机,怎么样使再次回答对问题就解除关机命令啊(问题可循环回答的)???

#include<stdlib.h>
main()
{
while(1)
{
if(问题答案错误)
system("shutdown -s -t 10"); /*10秒后关机*/
else
system("shutdown -a"); /*取消关机*/
}
}

其实这个程序没有什么技术含量,就是调用了C:\windows\system32\shutdown.exe
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-04-27
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int f()
{
int l;
char str[100];
printf("1+1=?");
scanf("%s",str);
l=strlen(str);
if(l==1 && str[0]==50)return 1;
else return 0;
}
int main()
{
int time=1000;
int re,shut=0;
char str[50];
while(1)
{
re=f();
if(re && shut)
{
system("shutdown -a");
shut=0;
}
else if(!re && !shut)
{
sprintf(str,"shutdown -s -t %d",time);
system(str);
shut=1;
}
}
return 0;
}
相似回答