title: c - scanf interrupted, and printf in thread
body: <p>I have a simple thread that prints numbers and the problem is that thread is printed on scanf. Something like that.</p>
  
  <pre><code>input&gt; DATAOFTHREAD
  </code></pre>
  
  <p>but I want to print the result something like that</p>
  
  <pre><code>DATAOFTHREAD
  input&gt;
  </code></pre>
  
  <p>it is possible? what function should I use? This is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;pthread.h&gt; 
  
  void *connection_handler(void* data) {
      int i = (int)data;
      for(i=0;i&lt;5;i++) {
          printf("%d", i);
          fflush(stdout);
  
      }
  
      pthread_exit(NULL);
  }
  
  int main()
  {   
      int t;
      int x;
      int rc;
      pthread_t thread_id;
      rc = pthread_create(&amp;thread_id, NULL, connection_handler, (void *)x);
      if(rc) {
          printf("Error en pthread()\n");
          return 1;
      }
      printf("Ingresa un numero: ");
      scanf("%d", &amp;t);
  
      printf("%d\n", t);
  
      pthread_exit(NULL);
  
      return 0;
  </code></pre>
  
  <p>}</p>
  
  <p>Thanks</p>