[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

getchar() problem

HI, I'm doing a unix programming. However, i get problem when I try to read some input from keyboard. I use "getchar()" to do it, however, the programming is justing waiting there until somebody key in something.  Is there a way to periodly check if there is any key-input in the input-buffer. If there is, then read the key. If not, continue to wait.  I have do this in DOS. However, I don't know how to do it in UNIX.  
0
wzou
Asked:
wzou
1 Solution
 
rbrCommented:
In Unix this problem is a little bit complicated. You have to use ioctl and
the read function. Use your manual, and if you are interessted in a programm
working with this send an email to rbr@physik.kfunigraz.ac.at. I'll send you
a demo program.
0
 
ozoCommented:
#include <time.h>
int select(size_t nfds, int *readfds, int *writefds, int *exceptfds, const struct timeval *timeout );

#include <curses.h>
halfdelay(1)

#include <fcntl.h>
fcntl(0, F_SETFL, O_NDELAY);

#include <termio.h>
termio.c_cc[VMIN] = 0;
termio.c_cc[VTIME] = 0;
0
 
wzouAuthor Commented:
Hi rbr,

Thanks for help. I will appreciate if you could send me the demo . My Email address is wzou@comp.uark.edu.

Best regards!!



0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now