1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

non blocking getchar.. is possible?

Discussion in 'C' started by sharingos, Apr 19, 2007.

  1. sharingos

    sharingos New Member

    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
    Code:
     c=getchar();	
    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
    Code:
    int kbhit(void)
    
    {
    
    struct timeval tv;
    
    fd_set read_fd;
    
    tv.tv_sec=0;
    
    tv.tv_usec=0;
    
    FD_ZERO(&read_fd);
    
    FD_SET(0,&read_fd);
    
    if(select(1, &read_fd, NULL, NULL, &tv) == -1)
    
    return 0;
    
    if(FD_ISSET(0,&read_fd))
    
    return 1;
    
    return 0;
    
    }
    
    
    and this code:
    Code:
    
    if (kbhit()) 
    	 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 :(

    hi!
     

Share This Page