Question: Let's say there's an object file input.obj. In the terminal, if I do "cat input.obj," it returns some random characters like "???A?J." But when I "hexdump" it, it shows the values I want to read in into my program.

I read in this obj file into program.c, firstly by opening it using fopen and read byte by byte using fgetc. However, it is actually reading the contents as shown in "cat input.obj," whereas I want it to read the actual contents as in hexdump. Any ideas?

Code snippet (from poster's comment):

```
 char *filename; 
 FILE *f; 
 char c; 
 f = fopen(filename, "r"); 
 c = fgetc(f);

```

Answer: 
Essentially, you need to print the integer representation of each byte to get what you want, not the byte itself. Try this:

```
char ch = ...; // Set ch to the value you read from the file
printf("%x", ch & 0xff);

```

The & 0xFF makes sure that the value is printed as 1 byte.
This was an issue which I had faced as well.
Surprisingly fopen and fgetc won't get the whole text file and will reach EOF without parsing the whole object file.

Use open() and read() system calls instead. You can check their syntax using man pages.

They give you the whole object file as seen when you do

$ hexdump -C 1\_hello.o