non blocking getchar.. big problem :(

Reply

Join Date: Apr 2007
Posts: 4
Reputation: kazuyaz is an unknown quantity at this point 
Solved Threads: 0
kazuyaz kazuyaz is offline Offline
Newbie Poster

non blocking getchar.. big problem :(

 
0
  #1
Apr 19th, 2007
hi,
does anyone knows if is there a way to make getchar non blocking?

I'm using curses and I'm on linux platform. With a thread version of the same program I have solved my problems with getch and with the timeout function but now the program doesn't work properly and I must use
  1.  
  2. c=getchar();
  3. if (c==0) c=getch();
Using timeout(1) makes non blocking only the c=getch part of this code but not the getchar one.

I have tried to solve this problem using this function
  1. int kbhit(void)
  2.  
  3. {
  4.  
  5. struct timeval tv;
  6.  
  7. fd_set read_fd;
  8.  
  9. tv.tv_sec=0;
  10.  
  11. tv.tv_usec=0;
  12.  
  13. FD_ZERO(&read_fd);
  14.  
  15. FD_SET(0,&read_fd);
  16.  
  17. if(select(1, &read_fd, NULL, NULL, &tv) == -1)
  18.  
  19. return 0;
  20.  
  21. if(FD_ISSET(0,&read_fd))
  22.  
  23. return 1;
  24.  
  25. return 0;
  26.  
  27. }

and this code
  1. if (kbhit())
  2. c = getchar();
but the program doesn't work properly...

Does anyone knows a solution?

I'm 5 days in a row searching of solve this big problem unhappy
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 4
Reputation: kazuyaz is an unknown quantity at this point 
Solved Threads: 0
kazuyaz kazuyaz is offline Offline
Newbie Poster

Re: non blocking getchar.. big problem :(

 
0
  #2
Apr 19th, 2007
does anyone has a idea?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: non blocking getchar.. big problem :(

 
0
  #3
Apr 19th, 2007
The solution is not to use functions that compromise portability.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 4
Reputation: kazuyaz is an unknown quantity at this point 
Solved Threads: 0
kazuyaz kazuyaz is offline Offline
Newbie Poster

Re: non blocking getchar.. big problem :(

 
0
  #4
Apr 19th, 2007
Originally Posted by iamthwee View Post
The solution is not to use functions that compromise portability.
yes, getchar() is portable however..
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 4
Reputation: kazuyaz is an unknown quantity at this point 
Solved Threads: 0
kazuyaz kazuyaz is offline Offline
Newbie Poster

Re: non blocking getchar.. big problem :(

 
0
  #5
Apr 23rd, 2007
no one?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC