I need to add a timeout function for getchar() in my program.
What do I do so that when my program reaches the instruction getchar(), it will only wait for a certai
This is usually achieved by using select() on stdin. Another solution would be using alarm() and a dummy SIGALRM handler to interrupt the getchar() call (only working on POSIX systems though).
select()
stdin
alarm()
getchar()