Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //imran rana
- #include <time.h>
- #include <iostream>
- #include <conio.h>
- #include<stdio.h>
- using namespace std;
- char* get_timed_input(long timeout_seconds, char* input_buffer,int buffer_size)
- {
- time_t start, now;
- int nChars = 0;
- int chr = 0;
- const int VK_RETURN = 13;
- // start timer
- time(&start);
- while( nChars < buffer_size && chr != VK_RETURN)
- {
- time(&now);
- if( (now-start) >= timeout_seconds)
- {
- // timeout
- input_buffer[nChars] ='\0';
- return NULL;
- }
- while( !_kbhit() )
- {
- time(&now);
- if( (now-start) >= timeout_seconds)
- {
- // timeout
- input_buffer[nChars] = '\0';
- return NULL;
- }
- }
- chr = getche();
- input_buffer[nChars++] = chr;
- }
- input_buffer[nChars] = '\0';
- return input_buffer;
- }
- int main()
- {
- char imran[500]= {0};
- get_timed_input(3,imran,500);
- printf("\n:) User Input : %s",imran);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement