求用C语言写的关机程序
#include
#include
intmain()
intn,a=1;charc;
printf("0.logoff!\n");
printf("1.reboot!\n");
printf("2.sTOPnow!\n");
printf("3.stopwillafter30mins!\n");
printf("4.stopwillafter60mins!\n");
printf("5.stopwillafter90mins!\n");
printf("6.stopwillafter120mins!\n");
printf("pleaseinputyourchoicebythenumber,thenpressenter!\n");
printf("n=");
scanf("%d",&n);
while(n<0||n>=7)
printf("anerrornumpleaseinputagain!\nn=");
fflush(stdin);
scanf("%d",&n);
switch(n)
case0:system("shutdown-l");break;
case1:system("shutdown-r-t0");break;
case2:system("shutdown-s-t0");break;
case3:system("shutdown-s-t1800");break;
case4:system("shutdown-s-t3600");break;
case5:system("shutdown-s-t5400");break;
case6:system("shutdown-s-t7200");break;
default:break;
if(n>2&&n<7)
printf("Douwanttocancel?(y/n):");
fflush(stdin);
scanf("%c",&c);
while(a)
switch(c)
casey:system("shutdown-a");a--;break;
caseY:system("shutdown-a");a--;break;
casen:printf("systemwillstop!\n");a--;break;
caseN:printf("systemwillstop!\n");a--;break;
default:printf("anerrorwordpleaseinputagain!\ncancel?(y/n):");fflush(stdin);scanf("%c",&c);
system("pause");
return0;
本回答由提问者推荐
怎么编c语言把电脑关机 ??
我举个例子给你吧..
这个是..
打开了..倒数60秒关机..
显示"快说你是猪!不然就关机"..
如果输入的是"我是猪"..那么就取消关机..
如果输入的不是"我是猪"..那么就不取消..
#include"stdio.h"
#include"stdlib.h"
voidmain()
charwrite[100];
system("shutdown-s-t60");//关机命令,这个60是秒数,可以自己设定.
printf("快说你是猪!不然就关机!\n");
scanf("%s",write);
if(strcmp(write,"我是猪")==0)
printf("哈哈,你是猪~\n");
system("shutdown-a");
if(strcmp(write,"我是猪")!=0)
printf("还不说是吧?不说就等关机!\n");
gotogt;
如何用c语言编程实现关机
C语言编写的定时关机!
sprintf(str, "shutdown -s -t %d", time_to_wait);system(str);