Link to home
Start Free TrialLog in
Avatar of william007
william007

asked on

About Manipulating Binary File

myFile.txt is a binary file:

Followed is the result of od -Ax -tx1 myFile.txt:
000000 68 01 00 00 a0 05 00 00 48 00 00 00 38 05 00 00
000010 53 01 00 00 01 00 00 00 00 00 00 00 00 00 00 00

Followed is the code
//myFile.txt is being memory map
            char * mf=mmap(0,n,PROT_READ,MAP_PRIVATE,f,0);
               int decArray=decArray[16];
            int i;
            for (i=0;i<16;i++){
                    //1. How to get the value of  mf[i], and print it on the screen, all in the format of 0x00**, eg 0x0068, 0x00a0?
                    //2. How to convert mf[i] in the decimal format and store it in the decArray?
            }

ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of william007
william007

ASKER

Hi for 1, the result is like this
68
1
0
0
ffffffa0
5
....
But what I want is
0x0068
0x0001
0x0000
0x0000
0x00a0
0x0005
is it possible?
Use %x and not %p as format specifier in printf ...
Hi sunnycoder, I have used the %x, I am using gcc in Linux FC 5.
hmmm ... use unsigned char * mf instead of char * mf
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks=)