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....

You need to loop the chars array. Something like:

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

Still doesnt work, now it doesnt want to print anything

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.