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?
}
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_
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use %x and not %p as format specifier in printf ...
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks=)
ASKER
68
1
0
0
ffffffa0
5
....
But what I want is
0x0068
0x0001
0x0000
0x0000
0x00a0
0x0005
is it possible?