title: Effective while loop condition for client choices (TCP connection in linux - C)
body: <p>I am trying to make a TCP  file transferconnection that enables the client to choose what "task" he wants to do (list files in directory, upload, download a file), but not terminate once he makes a choice.  Meaning he can do more than one choice per session.</p>
  
  <p>The problem I have is that in my implementation of the while loop on the server side:</p>
  
  <pre><code>while(n= read(sd,rbuf,BUFLEN)){
  
  
      if (rbuf[0] == 'R'){//CHANGE DIR
          //char *dircha;
  
          //read(sd, rbuf, BUFLEN);
  
  
          printf("ENTER change directory\n");
          //chdir(dircha);// this will change directory
      }
  
      if(rbuf[0] == 'L'){//LIST FILES
  
          requiem[0] = 'I';
          requiem[1] =  20;
          printf("TYPE: %c", requiem[0]);
          write(sd, requiem , 2);.... //rest of code
  </code></pre>
  
  <p>The rbuf doesnt get "cleared" and still contains the characters the client made when he typed his choices,  and once it enters the while loop and picks a choice, it will never be able to choose another task because rbuf[0] will never be equal to any of the choices i made.</p>
  
  <p>What can I do to make it so that the user can make multiple choices?  Thank you so much!</p>