title: How would I write a scanf() statement that only accepts certain characters?
body: <p>For a program I'm writing, I need to use <code>scanf()</code> to only scan in characters that are between 0-9, A-Z, and a-z.</p>
  
  <p>I figured I could use some nice comparison operators to help me accomplish my goal. For example, maybe this could work:</p>
  
  <pre><code>int i = 3;
  char a[7] = {'a', 'b', 'c', '?', 'e', 'f', '\0'};
  
  if (!(a[i] &gt;= '0' &amp;&amp; a[i] &lt;= '9') &amp;&amp; !(a[i] &gt;= 'A' &amp;&amp; a[i] &lt;= 'Z') &amp;&amp; !(a[i] &gt;= 'a' &amp;&amp; a[i] &lt;= 'z'))
    printf("not 0-9. A-Z, or a-z!\n");
  </code></pre>
  
  <p>In other words, if the character in <code>a[i]</code> is not a digit or a letter, then print the statement. But, that didn't work. Any alternatives?</p>