title: how to get a character from stdin without waiting for user to put it?
body: <p>I'm writing a C program that prints something on terminal using ncurses. It should stop printing when user press 's' and continue again when press 's'. How can I read a key from input without waiting user to press the key?</p>
  
  <p>I tried <code>getch()</code> and <code>getchar()</code> but they wait until a key is pressed...</p>
  
  <p><strong>Edit</strong></p>
  
  <p>This is my code:</p>
  
  <pre><code>int main(void)
  {
     initscr(); /* Start curses mode         */
     refresh(); /* Print it on to the real screen */
     int i = 0, j = 0;
     int state = 0;
     while (1)
     {
        cbreak();
        int c = getch(); /* Wait for user input */
        switch (c)
        {
           case 'q':
              endwin();
              return 0;
           case 'c':
              state = 1;
              break;
           case 's':
              state = 0;
              break;
           default:
              state = 1;
              break;
        }
        if(state)
        {
           move(i, j);
           i++;
           j++;
           printf("a");
           refresh();
        }
     }
     nocbreak();
     return 0;
  }
  </code></pre>
  
  <p><strong>EDIT 2</strong>
  This works well. I got 100 points :)</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;curses.h&gt;
  
  int main(void)
  {
     initscr();
     noecho();
     cbreak();         // don't interrupt for user input
     timeout(500);     // wait 500ms for key press
     int c = 0;        // command: [c|q|s]
     int s = 1;        // state: 1= print, 0= don't print ;-)
     int i = 0, j = 0;
     while (c != 'q')
     {
        int c = getch();
        switch (c)
        {
           case 'q':
              endwin();
              return 0;
           case 'c':
              s = 1;
              break;
           case 's':
              s = 0;
              break;
           default:
              break;
        }
        if (s)
        {
           move(i, j);
           printw("a");
           i++;
           j++;
        }
     }
     endwin();
     nocbreak();
     return 0;
  }
  </code></pre>