Write hex in text file to other file

Pages: 12
I tried it and it just outputed the hex as text.
I also tried it and it seems correct to me. I think the hex you provided do map to a lot of normal text, hence you seeing such result.

try changing your hex input such that you have non printable characters inserted or run your hex dumper on your output file and see if it matches your input file.
I tried that and it didnt work. It worked for you though? With me it adds spaces 3 extra spaces between characters.
try this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
   string strFile = "Test\\Hex.txt";
   string strBinFile = "Test\\Bin.bin";
   string strVal;

   char buffer[BUFFER_SIZE];
   ifstream fin(strFile.c_str());
   ofstream fout(strBinFile.c_str(), ios::out | ios::binary);
   
   for (int i=0; !fin.eof(); i++)
   {
      fin >> strVal;

      buffer[i] = HexByteStringToInt(strVal);
   }

   fout.write(buffer, i);
   fout.close();
   fin.close();
Topic archived. No new replies allowed.
Pages: 12