title: Using stdin with select() in C
body: <p>I have the following program:</p>
  
  <pre><code> #include &lt;stdio.h&gt;
   #define STDIN 0
  
   int main()
   {
  
      fd_set fds;
      int maxfd;
      // sd is a UDP socket
  
      maxfd = (sd &gt; STDIN)?sd:STDIN;
  
      while(1){
  
          FD_ZERO(&amp;fds);
          FD_SET(sd, &amp;fds); 
          FD_SET(STDIN, &amp;fds); 
  
          select(maxfd+1, &amp;fds, NULL, NULL, NULL); 
  
          if (FD_ISSET(STDIN, &amp;fds)){
                printf("\nUser input - stdin");
          }
          if (FD_ISSET(sd, &amp;fds)){
                // socket code
          }
       }
   }
  </code></pre>
  
  <p>The problem I face is that once input is detected on STDIN, the message "User input - stdin" keeps on printing...why doesn't it print just once and on next while loop check which of the descriptors has input ?</p>
  
  <p>Thanks.</p>