I wrote this code to read a file in c++
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <sstream>
    using namespace std;
    int main()
    {
        int addr;
        char op;
        FILE *fp;
        fp = fopen("test.txt","r");
        cout<<fp<<endl;
        while(EOF!=fscanf(fp,"%c""%x",&addr))
        {
            cout<<op<<endl<<hex<<addr<<endl;
        }
    }
I am getting a different output than the expected. The addr gets printed twice every time.
I want to read a file which looks like this:
r f1f
w f2f
r f3f
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.
 
    