title: Working with 2 threads handling I/O respectively on same terminal window in C
body: <p>I want to read input from a pthread using the terminal and output some text onto the same terminal using another pthread.</p>
  
  <p>However, the output from one of the pthread is being read by the other one.</p>
  
  <p>I read that ncurses may be used to divide the terminal and do both the stuff parallelly.</p>
  
  <p>Is there any other way to do this on the same terminal window?</p>
  
  <pre><code>void* send_message(){
      char message[MESSAGE_BUFFER_LEN];
      while(1){
          memset(message,'\0',sizeof(message));strcat(message,username);
          printf("%s",username);
          fgets(message+strlen(message),MESSAGE_BUFFER_LEN-strlen(username),stdin);
          sendAll(message,strlen(message));
      }
  }
  
  void* recieve_message(){
      char message[MESSAGE_BUFFER_LEN];
      while(1){
          recv(socket_fd,message,MESSAGE_BUFFER_LEN,0);
          printf("%s",message);
          memset(message,'\0',MESSAGE_BUFFER_LEN);
      }   
  }
  </code></pre>
  
  <p>The Input thread executes send_message and the output thread executes recieve_message.</p>
  
  <p>However, whatever the output thread prints onto the terminal is picked up by the Input Thread(send_message).</p>
  
  <p>I don't want that to happen.</p>
  
  <p>The best way out of it that I've found till now is to create two windows using ncurses and run output on one and input on another.</p>