Question: I need some C code (not C++) to read off a .obj file in binary and print out every two pieces of code in hex
I need some C code (not C++) to read off a .obj file in binary and print out every two pieces of code in hex format
For example, my .obj file has the characters:
45 00 20 09 E2 09 A4 09
and I need to convert this to hexadecimal format, with lowercase letters:
0x4500
0x2009
0xe209
0xa409
I've got the following code:

Copyable:
#include #include
int main(int argc, char *argv[]) { FILE *f; char *a; int i; short int b = 0; f=fopen(argv[1],"rb"); fseek(f,0,SEEK_END); long int size=ftell(f); a = (char *)malloc(sizeof(char)); fseek(f,0,SEEK_SET);
for(i=0;i a[i] = 0; fread(&a[i],sizeof(char),1,f); printf("0x%x\t ",a[i] & 0xff); } fclose(f); }
and this gives me the following output:

How can I edit my existing code, so that I get:
0x4500
0x2009
instead of:
0x45
0x0
0x20
0x9
Thank you.
# include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
