I wish to write a C program that reads in 1 byte hex values stored in a file. I have had a look around the Internet including StackOverflow but my requirement seems different from the average:
I have a text file with the following contents - which are single byte hex values:
35 36 37 38
In decimal that is:
53, 54, 55, 56
The hex values are the following ASCII characters
5 6 7 8
I want to read that in from a text file the which contains the ASCII 35 36 37 38
as four hex bytes. I have been tinkering with FILE
pointers and fread()
but it reads in the 35
value for example as 3
and 5
which is stored in a buffer as 33 35
(the hex for 3
and 5
separately). So my question is...
Short version:
Is there a way to read a file two ASCII characters at a time (not two bytes at a time because that would give different results!). Perhaps should I read into a char? Rather than presenting some code and stating it doesn't work as usually happens on SO, I'm not sure how to start with this so I have no code to present. You don't have to write the code for me but some guidance on how to approach the problem scenario would be good.