title: difference between scanf("%c" , ..) and getchar()
body: <p>I always think <code>scanf(&quot;%c&quot; , &amp;addr);</code> is equal to <code>getchar()</code> before I test this:</p>
  <pre><code>#include&lt;stdio.h&gt;
  
  int main()
  {
      int i;
      scanf(&quot;%c&quot;,&amp;i);
      printf(&quot;%d\n&quot;, i);
      if(i == EOF)
          printf(&quot;EOF int type and char input\n&quot;);
      i =getchar();
      printf(&quot;%d\n&quot;, i);
      if(i == EOF)
          printf(&quot;EOF int type and char input\n&quot;);
  }
  </code></pre>
  <p>I got output when I use &quot;Ctrl+D&quot; twice:</p>
  <blockquote>
  <p>-1217114112</p>
  <p>-1</p>
  <p>EOF int type and char input</p>
  </blockquote>
  <p>Since EOF is <code>-1</code> in <code>int</code> type ,I also try use <code>scanf(&quot;%d&quot;,&amp;i);</code> replace <code>scanf(&quot;%c&quot;,&amp;i)</code> , just get the same output.</p>
  <p>I got confused.  Can anybody explain this for me?</p>
  <p>----------------------------------EDIT-----------------------------------------------</p>
  <p>I want to know the behavior of <code>scanf(&quot;%c&quot;,i)</code> of Ctrl+D , I do test:</p>
  <pre><code>#include&lt;stdio.h&gt;
  
  int main()
  {
      int i;
      int j;
      j = scanf(&quot;%c&quot;,&amp;i);
      printf(&quot;%c\n&quot;, i);
      printf(&quot;%d\n&quot;, j);
      if(i == EOF)
          printf(&quot;EOF int type and char input&quot;);
       i =getchar();
      printf(&quot;%d\n&quot;, i);
      if(i == EOF)
          printf(&quot;EOF int type and char input&quot;);
  }
  </code></pre>
  <p>OutPut:</p>
  <pre><code>k                  // If the scanf set 1 byte in i , why here print 'k' ?
  -1
  -1
  EOF int type and char input
  </code></pre>