General discussion

Locked

Opening files in hex using Microsoft Vis

By mousy ·
How can I open a file for reading in hex format in C/C++?

The file contains a sequence of hex numbers that I need for calculations, so I should be able to read and use that data. Can anybody help me please?

This conversation is currently closed to new comments.

6 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Opening files in hex using Microsoft Vis

by pVp In reply to Opening files in hex usin ...

You're always reading files as a byte-stream anyway.

Use fread(), where you have to specify the number of bytes to read.

How you interpret the bytes is up to you.

Collapse -

Opening files in hex using Microsoft Vis

by mousy In reply to Opening files in hex usin ...
Collapse -

Opening files in hex using Microsoft Vis

by Sam Hobbs In reply to Opening files in hex usin ...

When you say hex, do you mean bianry or is the data composed of the characters '0'-'9' and 'A'-'F'?

If it is binary, and if you are using MFC, then I can provide you with sample code to read the file into a CString and then it can be processed there.

See: http://home.socal.rr.com/samhobbs/VC/EditCtrlRead.html

Collapse -

Opening files in hex using Microsoft Vis

by mousy In reply to Opening files in hex usin ...
Collapse -

Opening files in hex using Microsoft Vis

by lastorck In reply to Opening files in hex usin ...

I think you can use %x or %ux spec. in fscanf() or "hex" manipulator for fistream. If you read text file with hex values represented as strings in it of course.
Regards

Collapse -

Opening files in hex using Microsoft Vis

by mousy In reply to Opening files in hex usin ...
Back to Web Development Forum
6 total posts (Page 1 of 1)  

Related Discussions

Related Forums