I have the following program:
#include <stdio.h>
#define STDIN 0
int main()
{
fd_set fds;
int maxfd;
maxfd = (sd > STDIN)?sd:STDIN;
while(1){
FD_ZERO(&fds);
FD_SET(sd, &fds);
FD_SET(STDIN, &fds);
select(maxfd+1, &fds, NULL, NULL, NULL);
if (FD_ISSET(STDIN, &fds)){
printf("\nUser input - stdin");
}
if (FD_ISSET(sd, &fds)){
}
}
}
The problem I am facing is that as soon as the input is found in STDIN, the message "User input - stdin" continues to print ... why it does not print only once and the next, and the loop checks which of the descriptors has an input
Thanks.
source
share