title: Error while reading a file in c++
body: <p>I wrote this code to read a file in c++</p>
  
  <pre><code>    #include &lt;iostream&gt;
      #include &lt;fstream&gt;
      #include &lt;string&gt;
      #include &lt;sstream&gt;
      using namespace std;
  
      int main()
      {
          int addr;
          char op;
          FILE *fp;
          fp = fopen("test.txt","r");
          cout&lt;&lt;fp&lt;&lt;endl;
          while(EOF!=fscanf(fp,"%c""%x",&amp;addr))
          {
  
              cout&lt;&lt;op&lt;&lt;endl&lt;&lt;hex&lt;&lt;addr&lt;&lt;endl;
  
          }
      }
  </code></pre>
  
  <p>I am getting a different output than the expected. The addr gets printed twice every time.<br>
  I want to read a file which looks like this:
  r f1f
  w f2f
  r f3f</p>
  
  <p>When I remove the %c from the while loop i.e. the file contains only the address and not r/w, addr gets printed once which is as expected.</p>