title: Handling Non-Specified & Non-Empty Getch() (C program)
body: <p>I'm trying to handle when a user inputs something that is not specifically taken note of in the code. I'm using getch() and when a user inputs '1' there is a conditional that reacts to it; however, what I want to achieve is that if a user enters anything else another conditional will react to it. I would think this means to check if getch() != EOF and if getch() != '1' but I'm not getting the results I thought I would... sometimes the conditional hits, sometimes it doesn't. My code is below (remember to compile with -lncurses):</p>
  
  <pre><code>#include &lt;ncurses.h&gt;
  
  int main()
  {
      initscr();
  
      // makes user input immediately available
      cbreak();
  
      // makes getch() not echo user unput
      noecho();
  
      // if user input is excessive use the scroll to show it
      scrollok(stdscr, TRUE);
  
      // turns getch() into a non-blocking call
      nodelay(stdscr, TRUE);
  
      // loop forever
      while (true) {
  
          // if the user enters '1' its a hit
          if (getch() == '1') {
              printw("WHACK!\n");
          }
  
          // anything else is a miss
          if ( (getch() != '1') &amp;&amp; (getch() != EOF) ){
              printw("SWING AND A MISS!\n");
          }
  
          // sleep for 300 milliseconds
          napms(300);
          printw(".\n");
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Any help is appreciated.</p>