DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   reading a file in hex (http://www.daniweb.com/forums/thread150983.html)

Daco Oct 13th, 2008 7:40 pm
reading a file in hex
 
hey there everyone
i was working on a program of mine when that should read the file in hex and display the value of a certain hex address (0x000068FC as example).

but i have no clue where to begin except that ppl say it should work with fseek & fread
ive tried but i can't seem to work with it.
anyone might wanna help me with this?

thx
Daco

Ancient Dragon Oct 13th, 2008 7:49 pm
Re: reading a file in hex
 
post what you have tried. And post an example data file.

Daco Oct 13th, 2008 8:16 pm
Re: reading a file in hex
 
i didn't post code cause i knew i was totally wrong >_<

FILE *pFile;
char* buffer;
pFile = fopen("file.raw","rb");
//ill use the example address from original post
if(fseek(pFile, 0x000068FC, SEEK_SET))
{
//the 2 means to read 2 bytes right?
    fread(buffer,1,2,pFile);
fread(memory_card_content, 1, memory_card_size, pFile);
}
// final check to see what value buffer contains using command PanicAlert
PanicAlert("buffer = %x or %c",buffer,buffer");

Ancient Dragon Oct 13th, 2008 8:55 pm
Re: reading a file in hex
 
Also please post actual text of the assignment, not how you interpreted it.

Daco Oct 14th, 2008 5:55 am
Re: reading a file in hex
 
1 Attachment(s)
this is the file it should read in the code.
if that is what you mean

Ancient Dragon Oct 14th, 2008 7:44 am
Re: reading a file in hex
 
That wasn't what I meant -- There must have been more the the instructions your teacher gave you what what you posted because what you posted doesn't make any sense. Post exactly the words given to you.

Daco Oct 14th, 2008 7:55 am
Re: reading a file in hex
 
i dont follow coding classes. im doing this on my own.

ill explain all over again
when you hex edit a file you have a certain value on a certain address
for example you have value 04 on address 0x000068FC
my question was how do i check if hex address 0x000068FC has 04 as value

Ancient Dragon Oct 14th, 2008 8:37 am
Re: reading a file in hex
 
where did you get that address from? 68FCH == 26876 decimal. If that's the byte offset in the file where that value is found, then you should be able to just seek to that position and read that byte.


All times are GMT -4. The time now is 3:05 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC