c语言 kbhit()任意键返回问题!
#include<stdio.h>#include<stdlib.h>//支持dos命令函数system();#include<windows.h>//支持延时函数Sle...
#include <stdio.h>
#include <stdlib.h> //支持dos命令函数system();
#include <windows.h> //支持延时函数Sleep();
#include <conio.h>
void Shutdown();
void Clear();
int kbhit(void);
void main()
{
int number;
printf("Input the number to select:\n");
printf("1:Shutdown on 10s\n");
printf("2:Clean the trush\n");
scanf("%d",&number);
switch(number)
{
case 1:
Shutdown();
case 2:
Clear();
}
}
void Shutdown()
{
int time;
int key;
printf("Press any key to cancel!\n");
for(time=9;time>0;time--)
{
Sleep(1000);
printf("System will be shutdown on %d\n",time);
if(kbhit())
{
main(); //我想在按下任意键后返回主函数,否则往下执行。
}
}
system("shutdown -s -t 60"); //然而没有按下任意键执行了这段代码之后,还执行了Clear()函数!!!
}
void Clear()
{
system("c:/Clear.bat");
system("cls");
main();
}
求助!!! 展开
#include <stdlib.h> //支持dos命令函数system();
#include <windows.h> //支持延时函数Sleep();
#include <conio.h>
void Shutdown();
void Clear();
int kbhit(void);
void main()
{
int number;
printf("Input the number to select:\n");
printf("1:Shutdown on 10s\n");
printf("2:Clean the trush\n");
scanf("%d",&number);
switch(number)
{
case 1:
Shutdown();
case 2:
Clear();
}
}
void Shutdown()
{
int time;
int key;
printf("Press any key to cancel!\n");
for(time=9;time>0;time--)
{
Sleep(1000);
printf("System will be shutdown on %d\n",time);
if(kbhit())
{
main(); //我想在按下任意键后返回主函数,否则往下执行。
}
}
system("shutdown -s -t 60"); //然而没有按下任意键执行了这段代码之后,还执行了Clear()函数!!!
}
void Clear()
{
system("c:/Clear.bat");
system("cls");
main();
}
求助!!! 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询