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:

I need some C code (not C++) to read off a .obj

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:

file in binary and print out every two pieces of code in

How can I edit my existing code, so that I get:

0x4500

0x2009

instead of:

0x45

0x0

0x20

0x9

Thank you.

# include # include int main (int argc, char *argv[]) FILE *f; char *a int i; short int b-0; f-fopen (argv[1],"xb") fseek (E,O,SEEK END); long int size-ftell (f); a (char *)malloc (sizeof (char)) fseek (E,O,SEEK SET) for (1-0) ;i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!