First, sorry for my bad English. I'm using GetTickCount() function included in windows.h and getch() included in conio.h.
What I precisely want is to give user a time limit to input char. If time limit lapses, program continues to execute, skipping the wait for user to input the char.
char ch='A';
DWORD start_time, check_time;
start_time=GetTickCount();
check_time=start+500; //GetTickCount returns time in miliseconds, so I add 500 to wait input for half a second.
while (check_time>GetTickCount()) {
ch=getchar();
}
//do stuff with char with initial value of 'A' if user didn't enter another char during 500ms of wait.
But getchar() stops executing the program and waits for user to input char for indefinite time. Is there an easy solution to bypass this wait, and continue if 500ms passed?
EDIT:
Based on your tips, i wrote this and it works! Thank you guys!
while (!kbhit()&&(check_time>GetTickCount()))
{
if (kbhit())
{
ch=getch();
break;
}
}