Reputation: 773
I have a code here that would probably just delay 10 seconds before proceeding , but I want to add a feature that the user could wait that delay or press any key to continue, I know it wouldn't be just like delay(10000) || getch();
any way to do it?
#include <stdio.h>
#include <conio.h>
#include <dos.h>
void main(){
clrscr();
printf("Press Any Key or Wait for 10 Seconds to Continue");
delay(10000);
//getch();
}
Upvotes: 1
Views: 1930
Reputation: 17858
It's actually quite easy using alarm
:
printf("Press Any Key or Wait for 10 Seconds to Continue");
alarm(10);
getch();
alarm(0);
You might need to set a handler on SIGALRM
though.
Upvotes: 2
Reputation: 6911
#include <stdio.h>
#include <conio.h>
#include <dos.h>
void main()
{
int wait = 10000;
clrscr();
printf("Press Any Key or Wait for 10 Seconds to Continue\n");
while(!kbhit() && wait > 0)
{
delay(100);
wait -= 100;
}
}
Upvotes: 1