How to read a text file that contains hex code and compare it with hex code in another text file???

closed account (3hMz8vqX)
Hi all,
I need to search a text file for hexadecimal code from another text file...
This is the situation ...
I have two text files...
search.txt and code.txt...
Search.txt contains code to be searched for...
3A
4D
...etc
and code.txt
looks like this...
5A
6A
...etc
I need to check if all the hex code in search.txt matches with
the hex code in code.txt...
Please help:(
Thankyou everyone in advance!!! :)
Regards,
Aravind.
Last edited on
You could simply compare every byte sequentially. It doesn't matter that they contain hex code or not; it's still text, right?
Your example isn't very clear...

Can you clarify your examples?

Is code.txt binary and search.txt text?
Or are both text?
closed account (3hMz8vqX)
Okay,
both are text files ...
I need to search code.txt for hexadecimal digits in search.txt...
Please help:)
Thankyou everyone in advance!!! :)
Regards,
Aravind.
As I've said, you could just compare the files byte by byte. The easiest way is to open the first file, swallow it all inside a buffer, do the same with the second file, and then memcmp() them. Though it obviously won't work if you want to compare big files (larger than your available RAM).
closed account (3hMz8vqX)
Okay,
can you show me an example, please???
closed account (3hMz8vqX)
Okay,
I want to read the text file as :
 
file >> hex >> value;

and the second file as :
 
file2 >> hex >> val2;

and then do the comparison?
Thankyou everyone in advance!!! :)
Last edited on
Topic archived. No new replies allowed.