title: Ctrl-C eaten by getchar()
body: <p>I've been searching for a solution to my problem for a long time now that's why i'm turning to you:</p>
  
  <p>Consider this piece of code:</p>
  
  <pre><code>static char done = 0;
  static void sigHandler(void)
  {
      done = 1;
  }
  
  int user_input()
  {
      return (getchar() == 'q') ? 0 : 1;
  }
  
  int main(void)
  {
      signal(SIGTERM, sigHandler);
      signal(SIGINT, sigHandler);
      while (user_input() != 0 &amp;&amp; !done)
          usleep(1000);
      printf("exiting\n");
      return 0;
  }
  </code></pre>
  
  <p>Expected behavior:
  The program exits when user inputs q then enter. If <kbd>CTRL</kbd>+<kbd>C</kbd> is pressed, it is caught by the sigHandler function which sets the flag 'done' to 1 and exits the program.</p>
  
  <p>Observed behavior: 
  The <kbd>CTRL</kbd>+<kbd>C</kbd> character is eaten by the getchar() call, and the sigHandler function is never executed. When <kbd>CTRL</kbd>+<kbd>C</kbd> and then enter is pressed, the sigHandler function is called and the program exits.</p>
  
  <p>Could someone with more experience and knowledge help me on that one?</p>
  
  <p>Thanks for your input :)</p>