0

i have tried to write this hexdump code for dumping the contents of a tex file.

#include <iostream>
#include <fstream>
#include <string.h>

using namespace std;

int main()
{  
  string line;
  string finline;
  char infile[100];
  char ofile[100];
  char chars[750];

  cout<<"Enter input file: ";
  cin.ignore();
  cin.getline(infile, 99);
  cout<<"Enter output file: ";
  cin.getline(ofile, 99);

  ofstream out;
  out.open(ofile);

  ifstream file(infile);

  while(getline(file, line))
  {
    finline += line;
    for(int i = 0; i < finline.size(); i++)
    {
      chars[i] = finline[i];
    }
  }

  for(int i = 0; i < finline.size(); i++)
  {
    chars[i] = finline[i];
  }

  out<<hex<<(int)chars;
  cout<<hex<<(int)chars<<endl;

  return 0;
}

but it only give 1 line eg. 0b3d6fc9
and not as much as i think it should.

the file contains 3 lines of data, cant think that 3 lines can be in that 1 little hex line.

Anyway please help me write 1 that will work for dumping contents of files and maby even system memory, the files one is more important at the moment.

Thanks....

2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by MasterHacker110
0

You need to loop the chars array. Something like:

for (int i = 0; i < finline.size(); ++i) {
   cout << hex << chars[i];
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.