title: Getting a single digit of user input
body: <p>I'm a begginer and this is my first post so go easy on me :)</p>
  
  <p>Is there a better way of getting a single digit of user input, repeatedly?
  The input should consist only in a single digit followed by the return key.</p>
  
  <pre><code>for (int i = 0; i &lt; n; i++)
  {
      int foo = getchar() - '0';
      if (foo == '\n' - '0' || getchar() != '\n')
          return 1;
  }
  </code></pre>
  
  <p>Thanks in advance</p>
  
  <p>Paulo Ribeiro</p>
  
  <p>EDIT: After the loop I'm doing the following check.</p>
  
  <pre><code>switch (foo)
  {
      case 1:
          //do something
      case 2:
          //do something
      case 3:
          //do something
      default:
          return 1;
  }
  </code></pre>