-
Notifications
You must be signed in to change notification settings - Fork 0
/
khibitt.c
39 lines (29 loc) · 985 Bytes
/
khibitt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//Since conio.h is not available for mac os i have to take and use the kbhit(); function seperately by using it in a file and calling it
#include<stdio.h>
#include <sys/select.h>
#include"go.h"
int kbhit(void)
{
struct timeval tv;
fd_set read_fd;
/* Do not wait at all, not even a microsecond */
tv.tv_sec=0;
tv.tv_usec=0;
/* Must be done first to initialize read_fd */
FD_ZERO(&read_fd);
/* Makes select() ask if input is ready:
* 0 is the file descriptor for stdin */
FD_SET(0,&read_fd);
/* The first parameter is the number of the
* largest file descriptor to check + 1. */
if(select(1, &read_fd,NULL, /*No writes*/NULL, /*No exceptions*/&tv) == -1)
return 0; /* An error occured */
/* read_fd now holds a bit map of files that are
* readable. We test the entry for the standard
* input (file 0). */
if(FD_ISSET(0,&read_fd))
/* Character pending on stdin */
return 1;
/* no characters were pending */
return 0;
}